Skip to content

Commit 5a3c202

Browse files
authored
Merge pull request #6 from solverat/optional_options
Add Additional Configuration Options
2 parents bcc32d9 + cac155c commit 5a3c202

File tree

2 files changed

+120
-24
lines changed

2 files changed

+120
-24
lines changed

Api.php

Lines changed: 79 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ class Api
4141
'customerId' => null,
4242
'terminalId' => null,
4343
'sandbox' => null,
44-
'iframeCssUrl' => null,
44+
'interface' => null,
45+
'optionalParameters' => null,
4546
);
4647

4748
/**
@@ -121,11 +122,7 @@ public function initTransaction(array $model): array
121122
'ReturnUrls' => $model['ReturnUrls'],
122123
];
123124

124-
if (null !== $this->options['iframeCssUrl']) {
125-
$payload['Styling'] = [
126-
'CssUrl' => $this->options['iframeCssUrl'],
127-
];
128-
}
125+
$payload = $this->addOptionalInterfaceParams(Constants::INTERFACE_TRANSACTION, $payload);
129126

130127
$paymentMeans = $model['PaymentMeans'] ?? null;
131128

@@ -147,11 +144,7 @@ public function initPaymentPage(array $model): array
147144
'ReturnUrls' => $model['ReturnUrls'],
148145
];
149146

150-
if (null !== $this->options['iframeCssUrl']) {
151-
$payload['Styling'] = [
152-
'CssUrl' => $this->options['iframeCssUrl'],
153-
];
154-
}
147+
$payload = $this->addOptionalInterfaceParams(Constants::INTERFACE_PAYMENT_PAGE, $payload);
155148

156149
$notification = $model['Notification'] ?? null;
157150

@@ -261,4 +254,79 @@ public function getCaptureStrategy()
261254

262255
return Constants::INTERFACE_TRANSACTION;
263256
}
257+
258+
protected function addOptionalInterfaceParams(string $interface, array $payload): array
259+
{
260+
$allowedOptions = [
261+
Constants::INTERFACE_PAYMENT_PAGE => [
262+
'config_set',
263+
'payment_methods',
264+
'wallets',
265+
'notification_merchant_email',
266+
'notification_payer_email',
267+
'styling_css_url',
268+
'styling_content_security_enabled',
269+
'styling_theme',
270+
'payer_note',
271+
],
272+
Constants::INTERFACE_TRANSACTION => [
273+
'config_set',
274+
'payment_methods',
275+
'styling_css_url', // deprecated
276+
'styling_content_security_enabled',
277+
'styling_theme',
278+
'payer_note',
279+
]
280+
];
281+
282+
$optionalInterfaceOptions = $this->options['optionalParameters'] ?? [];
283+
284+
foreach ($optionalInterfaceOptions as $optionName => $optionValue) {
285+
286+
if (empty($optionValue)) {
287+
continue;
288+
}
289+
290+
if (!in_array($optionName, $allowedOptions[$interface])) {
291+
continue;
292+
}
293+
294+
switch($optionName) {
295+
case 'config_set':
296+
$payload['ConfigSet'] = (string) $optionValue;
297+
break;
298+
case 'payment_methods':
299+
$payload['PaymentMethods'] = explode(',', $optionValue);
300+
break;
301+
case 'wallets':
302+
$payload['Wallets'] = explode(',', $optionValue);
303+
break;
304+
case 'notification_merchant_email':
305+
$payload['Notification'] = $payload['Notification'] ?? [];
306+
$payload['Notification']['MerchantEmails'] = explode(',', $optionValue);
307+
break;
308+
case 'notification_payer_email':
309+
$payload['Notification'] = $payload['Notification'] ?? [];
310+
$payload['Notification']['PayerEmail'] = (string) $optionValue;
311+
break;
312+
case 'styling_css_url':
313+
$payload['Styling'] = $payload['Styling'] ?? [];
314+
$payload['Styling']['CssUrl'] = $optionValue;
315+
break;
316+
case 'styling_content_security_enabled':
317+
$payload['Styling'] = $payload['Styling'] ?? [];
318+
$payload['Styling']['ContentSecurityEnabled'] = $optionValue;
319+
break;
320+
case 'styling_theme':
321+
$payload['Styling'] = $payload['Styling'] ?? [];
322+
$payload['Styling']['Theme'] = $optionValue;
323+
break;
324+
case 'payer_note':
325+
$payload['PayerNote'] = $optionValue;
326+
break;
327+
}
328+
}
329+
330+
return $payload;
331+
}
264332
}

README.md

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ All features are covered with tests. You can find useful examples in functional
4444
## Installation
4545

4646
```bash
47-
$ composer require trackmage/payum-saferpay
47+
$ composer require karser/payum-saferpay
4848
```
4949

5050
## Configuration
@@ -80,14 +80,14 @@ payum:
8080
customerId: '401860'
8181
terminalId: '17795278'
8282
interface: 'TRANSACTION' #optionally, can be defined via details too
83+
optionalParameters: #optionally, add some additional interface options, read more below in section "Additional Configuration"
84+
styling_css_url: 'https://acme.com/hosted-page-styles.css'
8385
sandbox: true
84-
iframeCssUrl: 'https://acme.com/hosted-page-styles.css'
8586
```
8687

8788
### With Payum
8889

8990
```php
90-
<?php
9191
//config.php
9292
9393
use Payum\Core\GatewayFactoryInterface;
@@ -138,9 +138,7 @@ payum_capture_do:
138138

139139
Make sure you defined `Payment` and `Token` entities like it is described [here](https://github.com/Payum/Payum/blob/master/docs/storages.md)
140140

141-
142141
```php
143-
<?php
144142
//capture.php
145143
146144
use App\Entity\Payment;
@@ -173,7 +171,6 @@ $reply = $this->gateway->execute($captureRequest, true);
173171
```
174172

175173
```php
176-
<?php
177174
//done.php
178175
179176
use App\Entity\Payment;
@@ -196,11 +193,9 @@ $this->gateway->execute($status = new GetHumanStatus($payment));
196193
### Recurring Payments with the referenced transactions Method
197194

198195
1. Capture payment with Recurring or Installment option:
199-
200196
```php
201197
use Karser\PayumSaferpay\Constants;
202198
203-
204199
$payment = $storage->create();
205200
206201
$payment->setDetails(['Payment' => ['Recurring' => ['Initial' => true]]]);
@@ -212,7 +207,6 @@ $captureRequest = new Capture($token);
212207
$captureRequest->setModel($payment);
213208
$reply = $this->gateway->execute($captureRequest, true);
214209
//then redirect user to $reply->getUrl();
215-
216210
```
217211

218212
2. Capture a new transaction by providing a reference to the previous one:
@@ -237,7 +231,6 @@ $this->gateway->execute($captureRequest);
237231

238232
1. Obtaining the Alias:
239233
The user will have to enter their card details in an iframe.
240-
241234
```php
242235
use Karser\PayumSaferpay\Constants;
243236
use Karser\PayumSaferpay\Model\CardAlias;
@@ -335,18 +328,53 @@ class ConvertPaymentExtension implements ExtensionInterface
335328
}
336329
337330
```
338-
## Testing
339331

332+
### Additional Configuration
333+
Depending on given interface, there are several optional options available.
334+
335+
Example:
336+
337+
```yaml
338+
payum:
339+
gateways:
340+
saferpay:
341+
optionalParameters:
342+
styling_css_url: 'https://acme.com/hosted-page-styles.css'
343+
```
344+
345+
#### Payment Page interface
346+
| Key | Description |
347+
| --------------------------------------| ------------|
348+
| `config_set` | This parameter let you define your payment page config (PPConfig) by name. If this parameters is not set, your default PPConfig will be applied if available. When the PPConfig can't be found (e.g. wrong name), the Saferpay basic style will be applied to the payment page. |
349+
| `payment_methods` | Used to restrict the means of payment which are available to the payer for this transaction. If only one payment method id is set, the payment selection step will be skipped. |
350+
| `wallets` | Used to control if wallets should be enabled on the payment selection page and to go directly to the given wallet (if exactly one wallet is filled and PaymentMethods is not set). |
351+
| `notification_merchant_email` | Email addresses to which a confirmation email will be sent to the merchants after successful authorizations. |
352+
| `notification_payer_email` | Email address to which a confirmation email will be sent to the payer after successful authorizations. |
353+
| `styling_css_url` | Deprecated |
354+
| `styling_content_security_enabled` | When enabled, then ContentSecurity/SAQ-A is requested, which leads to the CSS being loaded from the saferpay server. |
355+
| `styling_theme` | This parameter let you customize the appearance of the displayed payment pages. Per default a lightweight responsive styling will be applied.If you don't want any styling use 'NONE'. |
356+
| `payer_note` | Text which will be printed on payer's debit note. Supported by SIX Acquiring. No guarantee that it will show up on the payer's debit note, because his bank has to support it too. Please note that maximum allowed characters are rarely supported. It's usually around 10-12. |
357+
358+
#### Transaction interface
359+
| Key | Description |
360+
| --------------------------------------| ------------|
361+
| `config_set` | This parameter let you define your payment page config (PPConfig) by name. If this parameters is not set, your default PPConfig will be applied if available. When the PPConfig can't be found (e.g. wrong name), the Saferpay basic style will be applied to the payment page. |
362+
| `payment_methods` | Used to restrict the means of payment which are available to the payer for this transaction. If only one payment method id is set, the payment selection step will be skipped. |
363+
| `styling_css_url` | Deprecated |
364+
| `styling_content_security_enabled` | When enabled, then ContentSecurity/SAQ-A is requested, which leads to the CSS being loaded from the saferpay server. |
365+
| `styling_theme` | This parameter let you customize the appearance of the displayed payment pages. Per default a lightweight responsive styling will be applied. If you don't want any styling use 'NONE'. |
366+
| `payer_note` | Text which will be printed on payer's debit note. Supported by SIX Acquiring. No guarantee that it will show up on the payer's debit note, because his bank has to support it too. Please note that maximum allowed characters are rarely supported. It's usually around 10-12. |
367+
368+
## Testing
340369
```
341370
composer update
342371
vendor/bin/phpunit
343372
```
344373
345-
346374
## ToDo
347375
- Implement separate actions: Authorize, Cancel transaction
348376
- Improve and add more unit tests
349-
- config parameters: LIABILITY_SHIFT condition, payer note
377+
- config parameters: LIABILITY_SHIFT condition
350378
351379
## Credits
352380
- Dmitrii Poddubnyi <dpoddubny@gmail.com>

0 commit comments

Comments
 (0)