Skip to content

Commit 7e7c88b

Browse files
committed
Tidy up payment type selection and documentation ro match.
1 parent c9705e6 commit 7e7c88b

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -257,17 +257,22 @@ and `brand`. Example:
257257
Alternatively a range of payment methods can be supplied as a JSON string:
258258

259259
```php
260-
'paymentMethods' => '[{"paymentType":"CC","brand":"VISA"},{"paymentType":"CC","brand":"MASTERCARD"},{"paymentType":"PAYPAL","brand":"PAYPAL"}]',
261-
262-
// alternatively:
260+
'paymentMethods' => [
261+
["paymentType" => "CC", "brand" => "VISA"],
262+
["paymentType" => "CC", "brand" => "MASTERCARD"],
263+
["paymentType" => "PAYPAL", "brand" => "PAYPAL"],
264+
],
263265

264-
'paymentMethods' => json_encode([
265-
['paymentType' => 'CC', 'brand' => 'VISA'],
266-
['paymentType' => 'CC', 'brand' => 'MASTERCARD'],
267-
['paymentType' => 'PAYPAL', 'brand' => 'PAYPAL'],
268-
]),
266+
// Or you can supply 'paymentMethods' as a JSON string.
269267
```
270268

269+
For some payment types the brand is mandatory and for some it is optional.
270+
Examples:
271+
272+
* `paymentType` "CC" and `brand` "VISA" will offer a visa card payment type only.
273+
* `paymentType` "CC" and no `brand` will offer a choice of all credit card types available.
274+
* No `paymentType` and no `brand` will offer a choice from all payment types available.
275+
271276
### Payment Page Complete Payment
272277

273278
The transaction is completed in exactly the same way as for the seamless payments.

src/ConstantsInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ interface ConstantsInterface
141141

142142
// The transaction was ok and the profile created
143143
const RETURN_CODE_PROFILE_CREATED = 'PROFILE_CREATED';
144+
// The transaction was ok and the profile created
145+
const RETURN_CODE_PROFILE_USED = 'PROFILE_USED';
144146
//The transaction was ok and the profile updated
145147
const RETURN_CODE_PROFILE_UPDATED = 'PROFILE_UPDATED';
146148
//The transaction was ok but the profile was not stored/updated

src/Messages/PaymentPage/PurchaseRequest.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,24 @@ public function sendData($data)
107107
$mdxi->Order->TemplateSet->setCSSName($data['cssName']);
108108
}
109109

110-
if (isset($data['paymentType']) && isset($data['brand'])) {
110+
if (isset($data['paymentType'])) {
111111
// A single payment type is requested.
112112

113-
$this->addPaymentType($mdxi, $data['paymentType'], $data['brand']);
113+
$this->addPaymentType($mdxi, $data['paymentType'], $data['brand'] ?? null);
114114
}
115115

116116
if (isset($data['paymentMethods'])) {
117117
// A list of payment types is requested for the payment page.
118118

119-
$paymentMethods = json_decode($data['paymentMethods'], true);
119+
if (is_string($data['paymentMethods'])) {
120+
$paymentMethods = json_decode($data['paymentMethods'], true);
121+
} else {
122+
$paymentMethods = $data['paymentMethods'];
123+
}
120124

121125
if (is_array($paymentMethods)) {
122126
foreach ($paymentMethods as $paymentMethod) {
123-
$this->addPaymentType($mdxi, $paymentMethod['paymentType'], $paymentMethod['brand']);
127+
$this->addPaymentType($mdxi, $paymentMethod['paymentType'], $paymentMethod['brand'] ?? null);
124128
}
125129
}
126130
}
@@ -216,7 +220,7 @@ public function sendData($data)
216220
/**
217221
* Add a single payment method to the mdxi object.
218222
*/
219-
protected function addPaymentType(Mpay24Order $mdxi, string $paymentType, string $brand)
223+
protected function addPaymentType(Mpay24Order $mdxi, string $paymentType, ?string $brand = null)
220224
{
221225
if ($this->paymentMethodCount === 0) {
222226
$mdxi->Order->PaymentTypes->setEnable('true');
@@ -225,6 +229,9 @@ protected function addPaymentType(Mpay24Order $mdxi, string $paymentType, string
225229
$this->paymentMethodCount++;
226230

227231
$mdxi->Order->PaymentTypes->Payment($this->paymentMethodCount)->setType($paymentType);
228-
$mdxi->Order->PaymentTypes->Payment($this->paymentMethodCount)->setBrand($brand);
232+
233+
if ($brand !== null) {
234+
$mdxi->Order->PaymentTypes->Payment($this->paymentMethodCount)->setBrand($brand);
235+
}
229236
}
230237
}

0 commit comments

Comments
 (0)