Skip to content

Commit

Permalink
Merge pull request #5 from io-digital/feature.send-unique-transaction-id
Browse files Browse the repository at this point in the history
saving merchant reference in results, allow pre-auth on card regsitra…
  • Loading branch information
garethnic authored Apr 30, 2020
2 parents 4b2634e + 543b341 commit 75e834e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
15 changes: 12 additions & 3 deletions src/Api/PaymentMethods/CopyAndPay.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,26 @@ public function getCheckoutRegistrationResult($path, $owner)
*
* @return mixed|\Psr\Http\Message\ResponseInterface
*/
public function registerCardDuringPayment(int $amount)
public function registerCardDuringPayment(int $amount, $preAuth = false)
{
return $this->client->request('POST', 'checkouts', [
$response = $this->client->request('POST', 'checkouts', [
'form_params' => [
'entityId' => $this->settings->getEntityIdOnceOff(),
'amount' => Currency::paymentFriendlyNumber($amount),
'currency' => 'ZAR',
'paymentType' => self::DEBIT,
'paymentType' => $preAuth == true ? self::PREAUTHORISATION : self::DEBIT,
'createRegistration' => true,
],
])->getBody()->getContents();

$result = json_decode($response, true);
$responseCheck = new Response();

if ($responseCheck->isSuccessfulResponse($result['result']['code'])) {
return $result['id'];
}

return false;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Api/PaymentMethods/ServerToServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public function repeatedPayment(PaymentCard $card, $owner, int $amount, string $
'currency' => 'ZAR',
'paymentType' => self::DEBIT,
'recurringType' => $type,
'merchantTransactionId' => class_basename($owner) . '-' . $owner->id
],
]
)->getBody()->getContents();
Expand Down
8 changes: 4 additions & 4 deletions src/Models/PaymentCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public function results()
}

public function saveResult($results, $owner)
{
{
$result = $this->results()->create([
'transaction_id' => $results['id'] ?? null,
'registration_id' => $results['registrationId'] ?? null,
'transaction_id' => $results['merchantTransactionId'] ?? null,
'registration_id' => $results['id'] ?? null,
'payment_type' => $results['paymentType'] ?? null,
'amount' => isset($results['amount']) ? ($results['amount'] * 100) : null,
'currency' => $results['currency'] ?? 'ZAR',
Expand All @@ -82,7 +82,7 @@ public static function create(array $attributes = [])
'holder' => $result['card']['holder'],
'expiry_month' => $result['card']['expiryMonth'],
'expiry_year' => $result['card']['expiryYear'],
'registration_id' => $result['id'],
'registration_id' => $result['registrationId'] ?? $result['id'],
];

$model = static::query()->create($formattedAttrs);
Expand Down

0 comments on commit 75e834e

Please sign in to comment.