Skip to content
Snippets Groups Projects

Resolve #3115858 "Merge with 3456047"

1 unresolved thread
@@ -6,6 +6,9 @@ use Drupal\commerce_order\Entity\OrderInterface;
@@ -6,6 +6,9 @@ use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\commerce_payment\Entity\PaymentInterface;
use Drupal\commerce_payment\Entity\PaymentInterface;
use Drupal\commerce_payment\Exception\PaymentGatewayException;
use Drupal\commerce_payment\Exception\PaymentGatewayException;
use Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\OffsitePaymentGatewayBase;
use Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\OffsitePaymentGatewayBase;
 
use Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\SupportsAuthorizationsInterface;
 
use Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\SupportsRefundsInterface;
 
use Drupal\commerce_price\Price;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Lock\LockBackendInterface;
use Drupal\Core\Lock\LockBackendInterface;
@@ -32,12 +35,12 @@ use Symfony\Component\HttpFoundation\Response;
@@ -32,12 +35,12 @@ use Symfony\Component\HttpFoundation\Response;
* payment_method_types = {"credit_card"},
* payment_method_types = {"credit_card"},
* )
* )
*/
*/
class Saferpay extends OffsitePaymentGatewayBase {
class Saferpay extends OffsitePaymentGatewayBase implements SupportsAuthorizationsInterface, SupportsRefundsInterface {
/**
/**
* The supported api version.
* The supported api version.
*/
*/
const API_VERSION = '1.10';
const API_VERSION = '1.40';
/**
/**
* Production api url.
* Production api url.
@@ -55,10 +58,20 @@ class Saferpay extends OffsitePaymentGatewayBase {
@@ -55,10 +58,20 @@ class Saferpay extends OffsitePaymentGatewayBase {
const SAFERPAY_CAPTURED = 'CAPTURED';
const SAFERPAY_CAPTURED = 'CAPTURED';
/**
/**
* Saferpay authorised status.
* Saferpay authorized status.
*/
*/
const SAFERPAY_AUTHORIZED = 'AUTHORIZED';
const SAFERPAY_AUTHORIZED = 'AUTHORIZED';
 
/**
 
* Saferpay canceled status.
 
*/
 
const SAFERPAY_CANCELED = 'CANCELED';
 
 
/**
 
* Saferpay pending status.
 
*/
 
const SAFERPAY_PENDING = 'PENDING';
 
/**
/**
* Logger.
* Logger.
*
*
@@ -128,6 +141,7 @@ class Saferpay extends OffsitePaymentGatewayBase {
@@ -128,6 +141,7 @@ class Saferpay extends OffsitePaymentGatewayBase {
'order_identifier' => '',
'order_identifier' => '',
'order_description' => '',
'order_description' => '',
'autocomplete' => TRUE,
'autocomplete' => TRUE,
 
'auto_capture_refunds' => TRUE,
'debug' => FALSE,
'debug' => FALSE,
'request_alias' => FALSE,
'request_alias' => FALSE,
'payment_methods' => [],
'payment_methods' => [],
@@ -201,24 +215,30 @@ class Saferpay extends OffsitePaymentGatewayBase {
@@ -201,24 +215,30 @@ class Saferpay extends OffsitePaymentGatewayBase {
'#required' => TRUE,
'#required' => TRUE,
];
];
$form['autocomplete'] = array(
$form['autocomplete'] = [
'#type' => 'checkbox',
'#type' => 'checkbox',
'#title' => $this->t('Auto Finalize payment by capture of transaction.'),
'#title' => $this->t('Auto Finalize payment by capture of transaction.'),
'#default_value' => $this->configuration['autocomplete'],
'#default_value' => $this->configuration['autocomplete'],
);
];
 
 
$form['auto_capture_refunds'] = [
 
'#type' => 'checkbox',
 
'#title' => $this->t('Auto Assert refunds.'),
 
'#default_value' => $this->configuration['auto_capture_refunds'],
 
];
$form['request_alias'] = array(
$form['request_alias'] = [
'#type' => 'checkbox',
'#type' => 'checkbox',
'#title' => $this->t('Request alias'),
'#title' => $this->t('Request alias'),
'#description' => $this->t('To be able to use this setting, Saferpay support must set this up for the configured account. <strong>Note</strong>: This will request an alias and make it available to third party code, but it will not create reusable payments yet.'),
'#description' => $this->t('To be able to use this setting, Saferpay support must set this up for the configured account. <strong>Note</strong>: This will request an alias and make it available to third party code, but it will not create reusable payments yet.'),
'#default_value' => $this->configuration['request_alias'],
'#default_value' => $this->configuration['request_alias'],
);
];
$form['debug'] = array(
$form['debug'] = [
'#type' => 'checkbox',
'#type' => 'checkbox',
'#title' => $this->t('Output more verbose debug log.'),
'#title' => $this->t('Output more verbose debug log.'),
'#default_value' => $this->configuration['debug'],
'#default_value' => $this->configuration['debug'],
);
];
if ($this->moduleHandler->moduleExists('token')) {
if ($this->moduleHandler->moduleExists('token')) {
$form['token_help'] = [
$form['token_help'] = [
@@ -248,6 +268,7 @@ class Saferpay extends OffsitePaymentGatewayBase {
@@ -248,6 +268,7 @@ class Saferpay extends OffsitePaymentGatewayBase {
$this->configuration['order_identifier'] = $values['order_identifier'];
$this->configuration['order_identifier'] = $values['order_identifier'];
$this->configuration['order_description'] = $values['order_description'];
$this->configuration['order_description'] = $values['order_description'];
$this->configuration['autocomplete'] = $values['autocomplete'];
$this->configuration['autocomplete'] = $values['autocomplete'];
 
$this->configuration['auto_capture_refunds'] = $values['auto_capture_refunds'];
$this->configuration['debug'] = $values['debug'];
$this->configuration['debug'] = $values['debug'];
$this->configuration['request_alias'] = $values['request_alias'];
$this->configuration['request_alias'] = $values['request_alias'];
$this->configuration['payment_methods'] = array_filter($values['payment_methods']);
$this->configuration['payment_methods'] = array_filter($values['payment_methods']);
@@ -257,20 +278,42 @@ class Saferpay extends OffsitePaymentGatewayBase {
@@ -257,20 +278,42 @@ class Saferpay extends OffsitePaymentGatewayBase {
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public function onReturn(OrderInterface $order, Request $request) {
public function onReturn(OrderInterface $order, Request $request) {
// The status is checked in
$lock_name = 'commerce_saferpay_process_payment:' . $order->uuid();
// \Drupal\commerce_saferpay\Plugin\Commerce\PaymentGateway\Saferpay::onNotify().
if ($this->lock->acquire($lock_name)) {
 
/** @var \Drupal\commerce_order\OrderStorage $order_storage */
 
$order_storage = $this->entityTypeManager->getStorage('commerce_order');
 
if (\method_exists($order_storage, 'loadForUpdate')) {
 
$order = $order_storage->loadForUpdate($order->id());
 
}
 
$payment_process_result = $this->processPayment($order);
 
if (!$payment_process_result) {
 
return new Response('Error while processing payment.', 400);
 
}
 
$this->lock->release($lock_name);
 
}
}
}
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public function onNotify(Request $request) {
public function onNotify(Request $request) {
 
// The saferpay webhook comes really fast nearly instantly.
 
// If that happens before the customer returns the order will be placed
 
// 2 times that's why we are waiting a bit before processing the webhook.
 
sleep(30);
 
$query = $request->query->all();
$query = $request->query->all();
if (empty($query['order'])) {
if (empty($query['order'])) {
return new Response('Missing order query parameter.', 400);
return new Response('Missing order query parameter.', 400);
}
}
 
$lock_name = 'commerce_saferpay_process_payment:' . $query['order'];
 
if (!$this->lock->acquire($lock_name)) {
 
// Return a 429 'Too Many Requests' response if the lock can't be acquired.
 
return new Response('Payment is currently being processed.', 429);
 
}
 
/** @var \Drupal\commerce_order\OrderStorage $order_storage */
/** @var \Drupal\commerce_order\OrderStorage $order_storage */
$order_storage = $this->entityTypeManager->getStorage('commerce_order');
$order_storage = $this->entityTypeManager->getStorage('commerce_order');
@@ -301,9 +344,85 @@ class Saferpay extends OffsitePaymentGatewayBase {
@@ -301,9 +344,85 @@ class Saferpay extends OffsitePaymentGatewayBase {
return new Response('Error while processing payment.', 400);
return new Response('Error while processing payment.', 400);
}
}
 
$this->lock->release($lock_name);
 
return new Response('OK', 200);
return new Response('OK', 200);
 
 
}
 
 
/**
 
* {@inheritdoc}
 
*/
 
public function capturePayment(PaymentInterface $payment, Price $amount = NULL) {
 
$this->assertPaymentState($payment, ['authorization']);
 
 
// If not specified, capture the entire amount.
 
$amount = $amount ?: $payment->getAmount();
 
 
// Disallow any amount larger than the payment amount.
 
if ($amount->getNumber() > $payment->getAmount()->getNumber()) {
 
$amount = $payment->getAmount();
 
}
 
 
$order = $payment->getOrder();
 
 
if ($payment->getRemoteId() && $capture_result = $this->transactionCapture($payment)) {
 
 
if ($capture_result->Status != static::SAFERPAY_CAPTURED) {
 
$this->logger->notice(
 
'Payment capture for order %order_id failed. Saferpay status was %status.',
 
[
 
'%order_id' => $order->id(),
 
'%status' => $capture_result->Status,
 
]
 
);
 
return;
 
}
 
 
$payment->setState('completed');
 
$payment->setRemoteState($capture_result->Status);
 
$payment->setAmount($amount);
 
$payment->save();
 
}
}
}
 
/**
 
* {@inheritdoc}
 
*/
 
public function voidPayment(PaymentInterface $payment) {
 
$this->assertPaymentState($payment, ['authorization']);
 
 
if ($payment->getRemoteId() && $this->transactionCancel($payment)) {
 
$payment->setState('canceled');
 
$payment->save();
 
}
 
}
 
 
/**
 
* {@inheritdoc}
 
*/
 
public function refundPayment(PaymentInterface $payment, Price $amount = NULL) {
 
$this->assertPaymentState($payment, ['completed', 'partially_refunded']);
 
// If not specified, refund the entire amount.
 
$amount = $amount ?: $payment->getAmount();
 
$this->assertRefundAmount($payment, $amount);
 
 
$old_refunded_amount = $payment->getRefundedAmount();
 
$new_refunded_amount = $old_refunded_amount->add($amount);
 
if ($new_refunded_amount->lessThan($payment->getAmount())) {
 
$payment->state = 'partially_refunded';
 
}
 
else {
 
$payment->state = 'refunded';
 
}
 
$payment->setRefundedAmount($new_refunded_amount);
 
 
if ($payment->getRemoteId() && $this->transactionRefund($payment, $amount)) {
 
$payment->save();
 
}
 
}
 
 
/**
/**
* Payment processing.
* Payment processing.
*
*
@@ -339,48 +458,53 @@ class Saferpay extends OffsitePaymentGatewayBase {
@@ -339,48 +458,53 @@ class Saferpay extends OffsitePaymentGatewayBase {
// First assert and get the token.
// First assert and get the token.
$assert_result = $this->paymentPageAssert($order);
$assert_result = $this->paymentPageAssert($order);
// @todo Log/store more stuff?
/*
$order_data = $order->getData('commerce_saferpay');
* SAFERPAY statuses: AUTHORIZED, CANCELED, CAPTURED, PENDING.
$order_data['transaction_id'] = $assert_result->Transaction->Id;
* Some payment methods like WLCRYPTOPAYMENTS
$order->setData('commerce_saferpay', $order_data)->save();
* Do not support authorization and are captured directly.
 
*/
 
$transaction_status = $assert_result->Transaction->Status;
 
$payment_state = $this->mapTransactionStatusToPaymentState($transaction_status);
// If authorized, capture.
// Prepare payment values.
if ($assert_result->Transaction->Status != static::SAFERPAY_AUTHORIZED) {
$this->logger->notice('Payment asserting for order %order_id failed. Saferpay status was %status. Saferpay transaction id was %transaction_id.', [
'%order_id' => $order->id(),
'%status' => $assert_result->Transaction->Status,
'%transaction_id' => $assert_result->Transaction->Id,
]);
return FALSE;
}
$payment_values = [
$payment_values = [
'state' => 'authorization',
'state' => $payment_state,
'amount' => $order->getTotalPrice(),
'amount' => $order->getTotalPrice(),
'payment_gateway' => $this->parentEntity->id(),
'payment_gateway' => $this->parentEntity->id(),
'order_id' => $order->id(),
'order_id' => $order->id(),
'test' => $this->getMode() == 'test',
'test' => $this->getMode() == 'test',
'remote_id' => $assert_result->Transaction->Id,
'remote_id' => $assert_result->Transaction->Id,
'remote_state' => $assert_result->Transaction->Status,
'remote_state' => $assert_result->Transaction->Status,
'authorized' => $this->time->getRequestTime(),
];
];
if ($this->configuration['autocomplete']) {
if ($transaction_status == static::SAFERPAY_AUTHORIZED) {
$capture_result = $this->transactionCapture($order);
$payment_values['authorized'] = $this->time->getRequestTime();
if ($capture_result->Status != static::SAFERPAY_CAPTURED) {
/** @var \Drupal\commerce_payment\Entity\PaymentInterface $payment */
$this->logger->notice('Payment capture for order %order_id failed. Saferpay status was %status.', [
$payment = $payment_storage->create($payment_values);
'%order_id' => $order->id(),
\Drupal::moduleHandler()->invokeAll('commerce_saferpay_assert_result', [$assert_result, $order, $payment]);
'%status' => $capture_result->Status,
]);
$payment->save();
return FALSE;
if ($this->configuration['autocomplete']) {
 
$capture_result = $this->transactionCapture($payment);
 
if ($capture_result->Status != static::SAFERPAY_CAPTURED) {
 
$this->logger->notice('Payment capture for order %order_id failed. Saferpay status was %status.', [
 
'%order_id' => $order->id(),
 
'%status' => $capture_result->Status,
 
]);
 
return $payment;
 
}
 
$payment->setRemoteState($capture_result->Status);
 
$payment->setState('completed');
 
$payment->save();
}
}
$payment_values['remote_state'] = $capture_result->Status;
$payment_values['state'] = 'completed';
}
}
$payment = $payment_storage->create($payment_values);
$this->logger->notice('Payment asserting for order %order_id %state. Saferpay status was %status. Saferpay transaction id was %transaction_id.', [
\Drupal::moduleHandler()->invokeAll('commerce_saferpay_assert_result', [$assert_result, $order, $payment]);
'%state' => $payment_state,
'%order_id' => $order->id(),
$payment->save();
'%status' => $assert_result->Transaction->Status,
 
'%transaction_id' => $assert_result->Transaction->Id,
 
]);
// @todo Create payment method when supported.
// @todo Create payment method when supported.
// https://www.drupal.org/project/commerce/issues/2838380.
// https://www.drupal.org/project/commerce/issues/2838380.
@@ -405,7 +529,8 @@ class Saferpay extends OffsitePaymentGatewayBase {
@@ -405,7 +529,8 @@ class Saferpay extends OffsitePaymentGatewayBase {
$order = $payment->getOrder();
$order = $payment->getOrder();
$currency_code = $payment->getAmount()->getCurrencyCode();
$currency_code = $payment->getAmount()->getCurrencyCode();
$amount = $this->minorUnitsConverter->toMinorUnits($order->getTotalPrice());
$amount = $this->minorUnitsConverter->toMinorUnits($order->getTotalPrice());
$description = $this->token->replace($this->configuration['order_description'], ['commerce_order' => $order], ['clear' => TRUE]);
 
$order_identifier = $this->token->replace($this->configuration['order_identifier'], ['commerce_order' => $order], ['clear' => TRUE]);
$data = [
$data = [
'TerminalId' => $this->configuration['terminal_id'],
'TerminalId' => $this->configuration['terminal_id'],
'Payment' => [
'Payment' => [
@@ -413,17 +538,24 @@ class Saferpay extends OffsitePaymentGatewayBase {
@@ -413,17 +538,24 @@ class Saferpay extends OffsitePaymentGatewayBase {
'Value' => $amount,
'Value' => $amount,
'CurrencyCode' => $currency_code,
'CurrencyCode' => $currency_code,
],
],
'OrderId' => $this->token->replace($this->configuration['order_identifier'], ['commerce_order' => $order]),
// In some cases the tokens cant be resolved add fallback here.
'Description' => $this->token->replace($this->configuration['order_description'], ['commerce_order' => $order]),
'OrderId' => !empty($order_identifier) ? $order_identifier : $order->id(),
 
'Description' => !empty($description) ? $description : $this->configuration['description'],
 
],
 
'ReturnUrl' => [
 
'Url' => $return_urls['Success'],
],
],
'Notification' => [
'Notification' => [
'NotifyUrl' => Url::fromRoute('commerce_payment.notify', ['commerce_payment_gateway' => $this->parentEntity->id()], [
'SuccessNotifyUrl' => Url::fromRoute('commerce_payment.notify', ['commerce_payment_gateway' => $this->parentEntity->id()], [
 
'absolute' => TRUE,
 
'query' => ['order' => $order->uuid()],
 
])->toString(),
 
'FailNotifyUrl' => Url::fromRoute('commerce_payment.notify', ['commerce_payment_gateway' => $this->parentEntity->id()], [
'absolute' => TRUE,
'absolute' => TRUE,
'query' => ['order' => $order->uuid()],
'query' => ['order' => $order->uuid()],
])->toString(),
])->toString(),
],
],
];
];
$data['ReturnUrls'] = $return_urls;
if (!empty($this->configuration['request_alias'])) {
if (!empty($this->configuration['request_alias'])) {
$data['RegisterAlias']['IdGenerator'] = 'RANDOM';
$data['RegisterAlias']['IdGenerator'] = 'RANDOM';
@@ -441,10 +573,11 @@ class Saferpay extends OffsitePaymentGatewayBase {
@@ -441,10 +573,11 @@ class Saferpay extends OffsitePaymentGatewayBase {
$saferpay_response = $this->doRequest('/Payment/v1/PaymentPage/Initialize', $order->uuid(), $data);
$saferpay_response = $this->doRequest('/Payment/v1/PaymentPage/Initialize', $order->uuid(), $data);
if ($this->configuration['debug']) {
if ($this->configuration['debug']) {
$this->logger->info('PaymentPage initialized. Request id (order uuid): %request_id. Token: %token. Expires: %expires.', [
$this->logger->info('PaymentPage initialized. Request id (order uuid): %request_id. Token: %token. Expires: %expires. Requestdata: %data', [
'%request_id' => $order->uuid(),
'%request_id' => $order->uuid(),
'%token' => $saferpay_response->Token,
'%token' => $saferpay_response->Token,
'%expires' => $saferpay_response->Expiration,
'%expires' => $saferpay_response->Expiration,
 
'%data' => json_encode($data),
]);
]);
}
}
@@ -479,17 +612,17 @@ class Saferpay extends OffsitePaymentGatewayBase {
@@ -479,17 +612,17 @@ class Saferpay extends OffsitePaymentGatewayBase {
/**
/**
* Transaction capture call.
* Transaction capture call.
*
*
* @param \Drupal\commerce_order\Entity\OrderInterface $order
* @param \Drupal\commerce_payment\Entity\PaymentInterface $payment
* The order object.
* The payment object.
*
*
* @return \stdClass
* @return \stdClass
* The result of the call.
* The result of the call.
*/
*/
public function transactionCapture(OrderInterface $order) {
public function transactionCapture(PaymentInterface $payment) {
$order_data = $order->getData('commerce_saferpay');
$order = $payment->getOrder();
$data = [
$data = [
'TransactionReference' => [
'TransactionReference' => [
'TransactionId' => $order_data['transaction_id'],
'TransactionId' => $payment->getRemoteId(),
],
],
];
];
@@ -506,6 +639,102 @@ class Saferpay extends OffsitePaymentGatewayBase {
@@ -506,6 +639,102 @@ class Saferpay extends OffsitePaymentGatewayBase {
return $saferpay_response;
return $saferpay_response;
}
}
 
 
/**
 
* Transaction cancel call.
 
*
 
* @param \Drupal\commerce_order\Entity\OrderInterface $order
 
* The order object.
 
*
 
* @return \stdClass
 
* The result of the call.
 
*/
 
public function transactionCancel(PaymentInterface $payment) {
 
$order = $payment->getOrder();
 
$data = [
 
'TransactionReference' => [
 
'TransactionId' => $payment->getRemoteId(),
 
],
 
];
 
 
$saferpay_response = $this->doRequest('/Payment/v1/Transaction/Cancel', $order->uuid(), $data);
 
 
if ($this->configuration['debug']) {
 
$this->logger->info('Transaction cancel call finished. Request id (order uuid): %request_id. Order: %order_id. Status: %status.',
 
[
 
'%request_id' => $order->uuid(),
 
'%order_id' => $order->id(),
 
'%status' => $saferpay_response->Status,
 
]
 
);
 
}
 
 
return $saferpay_response;
 
}
 
 
/**
 
* Transaction refund call.
 
*
 
* @param \Drupal\commerce_payment\Entity\PaymentInterface $payment
 
* The payment object.
 
* @param \Drupal\commerce_price\Price $amount
 
* The price object.
 
*
 
* @return \stdClass
 
* The result of the call.
 
*/
 
public function transactionRefund(PaymentInterface $payment, Price $amount) {
 
$order = $payment->getOrder();
 
 
// Calculate the amount in the form Saferpay expects it.
 
$amount_converted = $this->toMinorUnits($amount);
 
$currency_code = $amount->getCurrencyCode();
 
 
$data = [
 
'Refund' => [
 
'Description' => $this->t('Refund for order @number', ['@number' => $order->getOrderNumber()]),
 
'Amount' => [
 
'Value' => $amount_converted,
 
'CurrencyCode' => $currency_code,
 
],
 
'OrderId' => $this->token->replace($this->configuration['order_identifier'], ['commerce_order' => $order]),
 
],
 
'CaptureReference' => [
 
'CaptureId' => $payment->getRemoteId(),
 
],
 
];
 
 
$saferpay_response = $this->doRequest('/Payment/v1/Transaction/Refund', $order->uuid(), $data);
 
 
// Auto capture refund.
 
if ($this->configuration['auto_capture_refunds']) {
 
$transaction_id = !empty($saferpay_response->Transaction->Id) ? $saferpay_response->Transaction->Id : '';
 
if ($transaction_id) {
 
$data = [
 
'TransactionReference' => [
 
'TransactionId' => $transaction_id,
 
],
 
];
 
// Shortening by hash, because sending the combined ID will result in a server error.
 
$request_id = hash('md5', $order->uuid() . '_' . $transaction_id);
 
$saferpay_response = $this->doRequest('/Payment/v1/Transaction/Capture', $request_id, $data);
 
}
 
}
 
 
if ($this->configuration['debug']) {
 
$this->logger->info(
 
'Transaction refund call finished. Request id (order uuid): %request_id. Order: %order_id. Status: %status.',
 
[
 
'%request_id' => $order->uuid(),
 
'%order_id' => $order->id(),
 
'%status' => $saferpay_response->Status,
 
]
 
);
 
}
 
 
return $saferpay_response;
 
}
 
/**
/**
* Does a post request using defaults parameters.
* Does a post request using defaults parameters.
*
*
@@ -542,15 +771,6 @@ class Saferpay extends OffsitePaymentGatewayBase {
@@ -542,15 +771,6 @@ class Saferpay extends OffsitePaymentGatewayBase {
}
}
catch (\Exception $e) {
catch (\Exception $e) {
$log[] = "Exception: {$e->getMessage()}.";
$log[] = "Exception: {$e->getMessage()}.";
// @see https://saferpay.github.io/jsonapi/#errorhandling
$error_response = $e->getResponse()->getBody()->getContents();
if (!empty($error_response)) {
$error_response_content = json_decode($error_response);
$log[] = "Error name: {$error_response_content->ErrorName}";
$log[] = "Error message: {$error_response_content->ErrorMessage}";
}
throw new PaymentGatewayException(implode(' / ', $log));
throw new PaymentGatewayException(implode(' / ', $log));
}
}
@@ -627,6 +847,34 @@ class Saferpay extends OffsitePaymentGatewayBase {
@@ -627,6 +847,34 @@ class Saferpay extends OffsitePaymentGatewayBase {
return $this;
return $this;
}
}
 
/**
 
* Map the transaction status to a payment state.
 
*
 
* @param string $transaction_status
 
* The transaction status.
 
*
 
* @return string
 
* The payment state.
 
*/
 
protected function mapTransactionStatusToPaymentState($transaction_status) {
 
switch ($transaction_status) {
 
case static::SAFERPAY_AUTHORIZED:
 
return 'authorization';
 
 
case static::SAFERPAY_CAPTURED:
 
return 'completed';
 
 
case static::SAFERPAY_PENDING:
 
return 'pending';
 
 
case static::SAFERPAY_CANCELED:
 
return 'canceled';
 
 
default:
 
return 'failed';
 
}
 
}
 
/**
/**
* Returns a list of language codes supported by Saferpay.
* Returns a list of language codes supported by Saferpay.
*
*
@@ -668,11 +916,13 @@ class Saferpay extends OffsitePaymentGatewayBase {
@@ -668,11 +916,13 @@ class Saferpay extends OffsitePaymentGatewayBase {
*/
*/
protected function getSaferpayPaymentMethods() {
protected function getSaferpayPaymentMethods() {
return [
return [
 
'ACCOUNTTOACCOUNT' => $this->t('Account2Account'),
'ALIPAY' => $this->t('Alipay'),
'ALIPAY' => $this->t('Alipay'),
'AMEX' => $this->t('American Express'),
'AMEX' => $this->t('American Express'),
'BANCONTACT' => $this->t('Bancontact'),
'BANCONTACT' => $this->t('Bancontact'),
'BONUS' => $this->t('Bonus Card'),
'BONUS' => $this->t('Bonus Card'),
'DINERS' => $this->t('Diners Club'),
'DINERS' => $this->t('Diners Club'),
 
'CARD' => $this->t('Credit Card'),
'DIRECTDEBIT' => $this->t('BillPay Direct Debit'),
'DIRECTDEBIT' => $this->t('BillPay Direct Debit'),
'EPRZELEWY' => $this->t('ePrzelewy'),
'EPRZELEWY' => $this->t('ePrzelewy'),
'EPS' => $this->t('eps'),
'EPS' => $this->t('eps'),
@@ -680,20 +930,22 @@ class Saferpay extends OffsitePaymentGatewayBase {
@@ -680,20 +930,22 @@ class Saferpay extends OffsitePaymentGatewayBase {
'IDEAL' => $this->t('iDEAL'),
'IDEAL' => $this->t('iDEAL'),
'INVOICE' => $this->t('Invoice'),
'INVOICE' => $this->t('Invoice'),
'JCB' => $this->t('JCB'),
'JCB' => $this->t('JCB'),
 
'KLARNA' => $this->t('Klarna'),
'MAESTRO' => $this->t('Maestro Int.'),
'MAESTRO' => $this->t('Maestro Int.'),
'MASTERCARD' => $this->t('Mastercard'),
'MASTERCARD' => $this->t('Mastercard'),
'MYONE' => $this->t('MyOne'),
'MYONE' => $this->t('MyOne'),
 
'PAYCONIQ' => $this->t('PayConiq'),
 
'PAYDIREKT' => $this->t('PayDirekt'),
'PAYPAL' => $this->t('PayPal'),
'PAYPAL' => $this->t('PayPal'),
'PAYDIREKT' => $this->t('paydirekt'),
'POSTFINANCEPAY' => $this->t('PostFinance Pay'),
'POSTCARD' => $this->t('Postfinance Card'),
'POSTFINANCE' => $this->t('Postfinance eFinance'),
'SAFERPAYTEST' => $this->t('Saferpay Test'),
'SAFERPAYTEST' => $this->t('Saferpay Test'),
'SOFORT' => $this->t('SOFORT'),
'SOFORT' => $this->t('SOFORT'),
'TWINT' => $this->t('TWINT'),
'TWINT' => $this->t('TWINT'),
'UNIONPAY' => $this->t('Unionpay'),
'UNIONPAY' => $this->t('Unionpay'),
'VISA' => $this->t('VISA'),
'VISA' => $this->t('VISA'),
'VPAY' => $this->t('VPay'),
'WECHATPAY' => $this->t('WeChatPay'),
 
'WLCRYPTOPAYMENTS' => $this->t('Wirecard Crypto Payments'),
];
];
}
}
}
}
 
\ No newline at end of file
Loading