Skip to content

Fixes to allow handling of regular credit card transactions #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The following gateways are provided by this package:

You need to set your `merchantId`, `publicKey` and `privateKey`. Setting `testMode` to true will use the `sandbox` environment.

This gateway supports purchase through a token (payment nonce) only. You can generate a clientToken for Javascript:
This gateway supports purchase through a token (payment nonce), which is the method recommended by Braintree. You can generate a clientToken for Javascript:

```php
$clientToken = $gateway->clientToken()->send()->getToken();
Expand All @@ -45,6 +45,20 @@ $response = $gateway->purchase([
])->send();
```

It also supports making purchases when the credit card number is specified:

```php
$response = $gateway->purchase([
'amount' => '10.00',
'card' => [
'number' => '4111111111111111',
'expiryMonth' => '6',
'expiryYear' => '2025',
'cvv' => '123',
]
])->send();
```

For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay)
repository.

Expand Down
58 changes: 34 additions & 24 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,30 +373,40 @@ public function getCardData()
return [];
}

return [
'billing' => [
'company' => $card->getBillingCompany(),
'firstName' => $card->getBillingFirstName(),
'lastName' => $card->getBillingLastName(),
'streetAddress' => $card->getBillingAddress1(),
'extendedAddress' => $card->getBillingAddress2(),
'locality' => $card->getBillingCity(),
'postalCode' => $card->getBillingPostcode(),
'region' => $card->getBillingState(),
'countryName' => $card->getBillingCountry(),
],
'shipping' => [
'company' => $card->getShippingCompany(),
'firstName' => $card->getShippingFirstName(),
'lastName' => $card->getShippingLastName(),
'streetAddress' => $card->getShippingAddress1(),
'extendedAddress' => $card->getShippingAddress2(),
'locality' => $card->getShippingCity(),
'postalCode' => $card->getShippingPostcode(),
'region' => $card->getShippingState(),
'countryName' => $card->getShippingCountry(),
],
$number = $card->getNumber();
if ($number) {
$cardData['creditCard'] = [
'number' => $number,
'expirationDate' => sprintf('%s/%s', $card->getExpiryMonth(), $card->getExpiryYear()),
'cvv' => $card->getCvv(),
];
}

$cardData['billing'] = [
'company' => $card->getBillingCompany(),
'firstName' => $card->getBillingFirstName(),
'lastName' => $card->getBillingLastName(),
'streetAddress' => $card->getBillingAddress1(),
'extendedAddress' => $card->getBillingAddress2(),
'locality' => $card->getBillingCity(),
'postalCode' => $card->getBillingPostcode(),
'region' => $card->getBillingState(),
'countryName' => $card->getBillingCountry(),
];

$cardData['shipping'] = [
'company' => $card->getShippingCompany(),
'firstName' => $card->getShippingFirstName(),
'lastName' => $card->getShippingLastName(),
'streetAddress' => $card->getShippingAddress1(),
'extendedAddress' => $card->getShippingAddress2(),
'locality' => $card->getShippingCity(),
'postalCode' => $card->getShippingPostcode(),
'region' => $card->getShippingState(),
'countryName' => $card->getShippingCountry(),
];

return $cardData;
}

/**
Expand Down Expand Up @@ -461,7 +471,7 @@ public function getLineItems()

return $line_items;
}

protected function createResponse($data)
{
return $this->response = new Response($this, $data);
Expand Down
25 changes: 15 additions & 10 deletions src/Message/AuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,20 @@ public function getData()
'lineItems' => $this->getLineItems(),
];

// special validation
if ($this->getPaymentMethodToken()) {
$data['paymentMethodToken'] = $this->getPaymentMethodToken();
} elseif ($this->getToken()) {
$data['paymentMethodNonce'] = $this->getToken();
} elseif ($this->getCustomerId()) {
$data['customerId'] = $this->getCustomerId();
} else {
throw new InvalidRequestException('The token (payment nonce), paymentMethodToken or customerId field should be set.');
$cardData = $this->getCardData();

if (empty($cardData['creditCard']['number'])) {
// special validation if the card number
// is not specified
if ($this->getPaymentMethodToken()) {
$data['paymentMethodToken'] = $this->getPaymentMethodToken();
} elseif ($this->getToken()) {
$data['paymentMethodNonce'] = $this->getToken();
} elseif ($this->getCustomerId()) {
$data['customerId'] = $this->getCustomerId();
} else {
throw new InvalidRequestException('The token (payment nonce), paymentMethodToken or customerId field should be set.');
}
}

// Remove null values
Expand All @@ -58,7 +63,7 @@ public function getData()
}

$data += $this->getOptionData();
$data += $this->getCardData();
$data += $cardData;
$data['options']['submitForSettlement'] = false;

return $data;
Expand Down