Skip to content

Commit 75e834e

Browse files
authored
Merge pull request #5 from io-digital/feature.send-unique-transaction-id
saving merchant reference in results, allow pre-auth on card regsitra…
2 parents 4b2634e + 543b341 commit 75e834e

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

src/Api/PaymentMethods/CopyAndPay.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,26 @@ public function getCheckoutRegistrationResult($path, $owner)
117117
*
118118
* @return mixed|\Psr\Http\Message\ResponseInterface
119119
*/
120-
public function registerCardDuringPayment(int $amount)
120+
public function registerCardDuringPayment(int $amount, $preAuth = false)
121121
{
122-
return $this->client->request('POST', 'checkouts', [
122+
$response = $this->client->request('POST', 'checkouts', [
123123
'form_params' => [
124124
'entityId' => $this->settings->getEntityIdOnceOff(),
125125
'amount' => Currency::paymentFriendlyNumber($amount),
126126
'currency' => 'ZAR',
127-
'paymentType' => self::DEBIT,
127+
'paymentType' => $preAuth == true ? self::PREAUTHORISATION : self::DEBIT,
128128
'createRegistration' => true,
129129
],
130130
])->getBody()->getContents();
131+
132+
$result = json_decode($response, true);
133+
$responseCheck = new Response();
134+
135+
if ($responseCheck->isSuccessfulResponse($result['result']['code'])) {
136+
return $result['id'];
137+
}
138+
139+
return false;
131140
}
132141

133142
/**

src/Api/PaymentMethods/ServerToServer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public function repeatedPayment(PaymentCard $card, $owner, int $amount, string $
103103
'currency' => 'ZAR',
104104
'paymentType' => self::DEBIT,
105105
'recurringType' => $type,
106+
'merchantTransactionId' => class_basename($owner) . '-' . $owner->id
106107
],
107108
]
108109
)->getBody()->getContents();

src/Models/PaymentCard.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ public function results()
5252
}
5353

5454
public function saveResult($results, $owner)
55-
{
55+
{
5656
$result = $this->results()->create([
57-
'transaction_id' => $results['id'] ?? null,
58-
'registration_id' => $results['registrationId'] ?? null,
57+
'transaction_id' => $results['merchantTransactionId'] ?? null,
58+
'registration_id' => $results['id'] ?? null,
5959
'payment_type' => $results['paymentType'] ?? null,
6060
'amount' => isset($results['amount']) ? ($results['amount'] * 100) : null,
6161
'currency' => $results['currency'] ?? 'ZAR',
@@ -82,7 +82,7 @@ public static function create(array $attributes = [])
8282
'holder' => $result['card']['holder'],
8383
'expiry_month' => $result['card']['expiryMonth'],
8484
'expiry_year' => $result['card']['expiryYear'],
85-
'registration_id' => $result['id'],
85+
'registration_id' => $result['registrationId'] ?? $result['id'],
8686
];
8787

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

0 commit comments

Comments
 (0)