Skip to content

Commit

Permalink
Merge pull request #6 from solverat/optional_options
Browse files Browse the repository at this point in the history
Add Additional Configuration Options
  • Loading branch information
solverat authored Jun 10, 2020
2 parents bcc32d9 + cac155c commit 5a3c202
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 24 deletions.
90 changes: 79 additions & 11 deletions Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class Api
'customerId' => null,
'terminalId' => null,
'sandbox' => null,
'iframeCssUrl' => null,
'interface' => null,
'optionalParameters' => null,
);

/**
Expand Down Expand Up @@ -121,11 +122,7 @@ public function initTransaction(array $model): array
'ReturnUrls' => $model['ReturnUrls'],
];

if (null !== $this->options['iframeCssUrl']) {
$payload['Styling'] = [
'CssUrl' => $this->options['iframeCssUrl'],
];
}
$payload = $this->addOptionalInterfaceParams(Constants::INTERFACE_TRANSACTION, $payload);

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

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

if (null !== $this->options['iframeCssUrl']) {
$payload['Styling'] = [
'CssUrl' => $this->options['iframeCssUrl'],
];
}
$payload = $this->addOptionalInterfaceParams(Constants::INTERFACE_PAYMENT_PAGE, $payload);

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

Expand Down Expand Up @@ -261,4 +254,79 @@ public function getCaptureStrategy()

return Constants::INTERFACE_TRANSACTION;
}

protected function addOptionalInterfaceParams(string $interface, array $payload): array
{
$allowedOptions = [
Constants::INTERFACE_PAYMENT_PAGE => [
'config_set',
'payment_methods',
'wallets',
'notification_merchant_email',
'notification_payer_email',
'styling_css_url',
'styling_content_security_enabled',
'styling_theme',
'payer_note',
],
Constants::INTERFACE_TRANSACTION => [
'config_set',
'payment_methods',
'styling_css_url', // deprecated
'styling_content_security_enabled',
'styling_theme',
'payer_note',
]
];

$optionalInterfaceOptions = $this->options['optionalParameters'] ?? [];

foreach ($optionalInterfaceOptions as $optionName => $optionValue) {

if (empty($optionValue)) {
continue;
}

if (!in_array($optionName, $allowedOptions[$interface])) {
continue;
}

switch($optionName) {
case 'config_set':
$payload['ConfigSet'] = (string) $optionValue;
break;
case 'payment_methods':
$payload['PaymentMethods'] = explode(',', $optionValue);
break;
case 'wallets':
$payload['Wallets'] = explode(',', $optionValue);
break;
case 'notification_merchant_email':
$payload['Notification'] = $payload['Notification'] ?? [];
$payload['Notification']['MerchantEmails'] = explode(',', $optionValue);
break;
case 'notification_payer_email':
$payload['Notification'] = $payload['Notification'] ?? [];
$payload['Notification']['PayerEmail'] = (string) $optionValue;
break;
case 'styling_css_url':
$payload['Styling'] = $payload['Styling'] ?? [];
$payload['Styling']['CssUrl'] = $optionValue;
break;
case 'styling_content_security_enabled':
$payload['Styling'] = $payload['Styling'] ?? [];
$payload['Styling']['ContentSecurityEnabled'] = $optionValue;
break;
case 'styling_theme':
$payload['Styling'] = $payload['Styling'] ?? [];
$payload['Styling']['Theme'] = $optionValue;
break;
case 'payer_note':
$payload['PayerNote'] = $optionValue;
break;
}
}

return $payload;
}
}
54 changes: 41 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ All features are covered with tests. You can find useful examples in functional
## Installation

```bash
$ composer require trackmage/payum-saferpay
$ composer require karser/payum-saferpay
```

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

### With Payum

```php
<?php
//config.php
use Payum\Core\GatewayFactoryInterface;
Expand Down Expand Up @@ -138,9 +138,7 @@ payum_capture_do:

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


```php
<?php
//capture.php
use App\Entity\Payment;
Expand Down Expand Up @@ -173,7 +171,6 @@ $reply = $this->gateway->execute($captureRequest, true);
```

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

1. Capture payment with Recurring or Installment option:

```php
use Karser\PayumSaferpay\Constants;
$payment = $storage->create();
$payment->setDetails(['Payment' => ['Recurring' => ['Initial' => true]]]);
Expand All @@ -212,7 +207,6 @@ $captureRequest = new Capture($token);
$captureRequest->setModel($payment);
$reply = $this->gateway->execute($captureRequest, true);
//then redirect user to $reply->getUrl();
```

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

1. Obtaining the Alias:
The user will have to enter their card details in an iframe.

```php
use Karser\PayumSaferpay\Constants;
use Karser\PayumSaferpay\Model\CardAlias;
Expand Down Expand Up @@ -335,18 +328,53 @@ class ConvertPaymentExtension implements ExtensionInterface
}
```
## Testing

### Additional Configuration
Depending on given interface, there are several optional options available.

Example:

```yaml
payum:
gateways:
saferpay:
optionalParameters:
styling_css_url: 'https://acme.com/hosted-page-styles.css'
```

#### Payment Page interface
| Key | Description |
| --------------------------------------| ------------|
| `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. |
| `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. |
| `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). |
| `notification_merchant_email` | Email addresses to which a confirmation email will be sent to the merchants after successful authorizations. |
| `notification_payer_email` | Email address to which a confirmation email will be sent to the payer after successful authorizations. |
| `styling_css_url` | Deprecated |
| `styling_content_security_enabled` | When enabled, then ContentSecurity/SAQ-A is requested, which leads to the CSS being loaded from the saferpay server. |
| `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'. |
| `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. |

#### Transaction interface
| Key | Description |
| --------------------------------------| ------------|
| `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. |
| `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. |
| `styling_css_url` | Deprecated |
| `styling_content_security_enabled` | When enabled, then ContentSecurity/SAQ-A is requested, which leads to the CSS being loaded from the saferpay server. |
| `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'. |
| `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. |

## Testing
```
composer update
vendor/bin/phpunit
```
## ToDo
- Implement separate actions: Authorize, Cancel transaction
- Improve and add more unit tests
- config parameters: LIABILITY_SHIFT condition, payer note
- config parameters: LIABILITY_SHIFT condition
## Credits
- Dmitrii Poddubnyi <dpoddubny@gmail.com>
Expand Down

0 comments on commit 5a3c202

Please sign in to comment.