Loading config/schema/commerce_wallee.schema.yml +7 −1 Original line number Diff line number Diff line Loading @@ -11,3 +11,9 @@ commerce_payment.commerce_payment_gateway.plugin.wallee_redirect_checkout: secret: type: string label: 'API Secret' payment_configuration: type: string label: 'Enabled payment method' payment_reusable: type: string label: 'Reusable payment method' src/Plugin/Commerce/CheckoutPane/PaymentInformation.php +3 −4 Original line number Diff line number Diff line Loading @@ -40,14 +40,14 @@ class PaymentInformation extends BasePaymentInformation { $payment_gateway = \Drupal::entityTypeManager()->getStorage('commerce_payment_gateway')->load($payment_method); if ($payment_gateway instanceof \Drupal\commerce_payment\Entity\PaymentGateway) { $plugin_configuration = $payment_gateway->getPluginConfiguration(); if (isset($plugin_configuration['payment_reusable']) AND $plugin_configuration['payment_reusable']) { if ($plugin_configuration['payment_reusable'] == 'ask') { // Check if user has set a value on last checkout. $tempstore = \Drupal::service('tempstore.private'); $store = $tempstore->get('commerce_wallee'); $pane_form['save_payment'] = [ '#type' => 'checkbox', '#title' => $this->t('Save payment information for resuable'), '#title' => $this->t('Save payment information'), '#description' => $this->t('Only for Visa, Master and Paypal'), '#default_value' => $store->get('save_payment', FALSE), ]; Loading @@ -73,7 +73,6 @@ class PaymentInformation extends BasePaymentInformation { $tempstore = \Drupal::service('tempstore.private'); $store = $tempstore->get('commerce_wallee'); $store->set('save_payment', $save_payment); $store->set('uid', \Drupal::currentUser()->id()); } } } src/Plugin/Commerce/PaymentGateway/RedirectCheckout.php +22 −4 Original line number Diff line number Diff line Loading @@ -123,6 +123,19 @@ class RedirectCheckout extends OffsitePaymentGatewayBase implements RedirectChec ); } /** * {@inheritdoc} */ public function defaultConfiguration() { return parent::defaultConfiguration() + [ 'space_id' => '', 'user_id' => '', 'secret' => '', 'payment_configuration' => 'all', 'payment_reusable' => 'ask', ]; } /** * {@inheritdoc} */ Loading Loading @@ -186,10 +199,15 @@ class RedirectCheckout extends OffsitePaymentGatewayBase implements RedirectChec // Allow user to save token. $form['payment_reusable'] = [ '#type' => 'checkbox', '#title' => $this->t('Allow user to use this for reusable'), '#description' => $this->t('Wallee allow right now only Visa, Master and Paypal'), '#type' => 'select', '#title' => $this->t('Request token and create reusable payment method'), '#description' => $this->t('Allows to reuse the payment information for additional payments. Wallee allows right now only Visa, Master and Paypal.'), '#default_value' => $this->configuration['payment_reusable'], '#options' => [ 'always' => $this->t('Always, payment methods are created for logged in users only'), 'ask' => $this->t('Ask the user'), 'never' => $this->t('Never'), ] ]; // Webhook configuration. Loading src/Services/PaymentSdk.php +27 −13 Original line number Diff line number Diff line Loading @@ -164,19 +164,11 @@ class PaymentSdk implements PaymentSdkInterface { $transactionPayload->setAllowedPaymentMethodConfigurations($pluginConfiguration['payment_configuration']); } // Get user settings. if (\Drupal::currentUser()->id() != 0) { // Get user temp store. $tempstore = \Drupal::service('tempstore.private'); $store = $tempstore->get('commerce_wallee'); $save_payment = $store->get('save_payment', 0); $uid = $store->get('uid', 0); if ($save_payment == TRUE) { if ($this->shouldRequestToken($pluginConfiguration)) { // Force token generation on wallee. $transactionPayload->setTokenizationMode(\Wallee\Sdk\Model\TokenizationMode::FORCE_CREATION_WITH_ONE_CLICK_PAYMENT); $transactionPayload->setCustomerEmailAddress($transactionPayload->getBillingAddress()->getEmailAddress()); $transactionPayload->setCustomerId($uid); } $transactionPayload->setCustomerId(\Drupal::currentUser()->id()); } // Allow alter transaction over hook. Loading Loading @@ -694,4 +686,26 @@ class PaymentSdk implements PaymentSdkInterface { return $card_type; } /** * Returns whether a token should be rquested. * * @param array $plugin_configuration * The payment gateway plugin configuration. * * @return bool * TRUE if a token should be requested. */ protected function shouldRequestToken(array $plugin_configuration) { if ($plugin_configuration['payment_reusable'] == 'always') { return TRUE; } if ($plugin_configuration['payment_reusable'] == 'ask' && \Drupal::currentUser()->id() != 0) { // Get user temp store. $tempstore = \Drupal::service('tempstore.private'); $store = $tempstore->get('commerce_wallee'); return $store->get('save_payment', FALSE); } } } Loading
config/schema/commerce_wallee.schema.yml +7 −1 Original line number Diff line number Diff line Loading @@ -11,3 +11,9 @@ commerce_payment.commerce_payment_gateway.plugin.wallee_redirect_checkout: secret: type: string label: 'API Secret' payment_configuration: type: string label: 'Enabled payment method' payment_reusable: type: string label: 'Reusable payment method'
src/Plugin/Commerce/CheckoutPane/PaymentInformation.php +3 −4 Original line number Diff line number Diff line Loading @@ -40,14 +40,14 @@ class PaymentInformation extends BasePaymentInformation { $payment_gateway = \Drupal::entityTypeManager()->getStorage('commerce_payment_gateway')->load($payment_method); if ($payment_gateway instanceof \Drupal\commerce_payment\Entity\PaymentGateway) { $plugin_configuration = $payment_gateway->getPluginConfiguration(); if (isset($plugin_configuration['payment_reusable']) AND $plugin_configuration['payment_reusable']) { if ($plugin_configuration['payment_reusable'] == 'ask') { // Check if user has set a value on last checkout. $tempstore = \Drupal::service('tempstore.private'); $store = $tempstore->get('commerce_wallee'); $pane_form['save_payment'] = [ '#type' => 'checkbox', '#title' => $this->t('Save payment information for resuable'), '#title' => $this->t('Save payment information'), '#description' => $this->t('Only for Visa, Master and Paypal'), '#default_value' => $store->get('save_payment', FALSE), ]; Loading @@ -73,7 +73,6 @@ class PaymentInformation extends BasePaymentInformation { $tempstore = \Drupal::service('tempstore.private'); $store = $tempstore->get('commerce_wallee'); $store->set('save_payment', $save_payment); $store->set('uid', \Drupal::currentUser()->id()); } } }
src/Plugin/Commerce/PaymentGateway/RedirectCheckout.php +22 −4 Original line number Diff line number Diff line Loading @@ -123,6 +123,19 @@ class RedirectCheckout extends OffsitePaymentGatewayBase implements RedirectChec ); } /** * {@inheritdoc} */ public function defaultConfiguration() { return parent::defaultConfiguration() + [ 'space_id' => '', 'user_id' => '', 'secret' => '', 'payment_configuration' => 'all', 'payment_reusable' => 'ask', ]; } /** * {@inheritdoc} */ Loading Loading @@ -186,10 +199,15 @@ class RedirectCheckout extends OffsitePaymentGatewayBase implements RedirectChec // Allow user to save token. $form['payment_reusable'] = [ '#type' => 'checkbox', '#title' => $this->t('Allow user to use this for reusable'), '#description' => $this->t('Wallee allow right now only Visa, Master and Paypal'), '#type' => 'select', '#title' => $this->t('Request token and create reusable payment method'), '#description' => $this->t('Allows to reuse the payment information for additional payments. Wallee allows right now only Visa, Master and Paypal.'), '#default_value' => $this->configuration['payment_reusable'], '#options' => [ 'always' => $this->t('Always, payment methods are created for logged in users only'), 'ask' => $this->t('Ask the user'), 'never' => $this->t('Never'), ] ]; // Webhook configuration. Loading
src/Services/PaymentSdk.php +27 −13 Original line number Diff line number Diff line Loading @@ -164,19 +164,11 @@ class PaymentSdk implements PaymentSdkInterface { $transactionPayload->setAllowedPaymentMethodConfigurations($pluginConfiguration['payment_configuration']); } // Get user settings. if (\Drupal::currentUser()->id() != 0) { // Get user temp store. $tempstore = \Drupal::service('tempstore.private'); $store = $tempstore->get('commerce_wallee'); $save_payment = $store->get('save_payment', 0); $uid = $store->get('uid', 0); if ($save_payment == TRUE) { if ($this->shouldRequestToken($pluginConfiguration)) { // Force token generation on wallee. $transactionPayload->setTokenizationMode(\Wallee\Sdk\Model\TokenizationMode::FORCE_CREATION_WITH_ONE_CLICK_PAYMENT); $transactionPayload->setCustomerEmailAddress($transactionPayload->getBillingAddress()->getEmailAddress()); $transactionPayload->setCustomerId($uid); } $transactionPayload->setCustomerId(\Drupal::currentUser()->id()); } // Allow alter transaction over hook. Loading Loading @@ -694,4 +686,26 @@ class PaymentSdk implements PaymentSdkInterface { return $card_type; } /** * Returns whether a token should be rquested. * * @param array $plugin_configuration * The payment gateway plugin configuration. * * @return bool * TRUE if a token should be requested. */ protected function shouldRequestToken(array $plugin_configuration) { if ($plugin_configuration['payment_reusable'] == 'always') { return TRUE; } if ($plugin_configuration['payment_reusable'] == 'ask' && \Drupal::currentUser()->id() != 0) { // Get user temp store. $tempstore = \Drupal::service('tempstore.private'); $store = $tempstore->get('commerce_wallee'); return $store->get('save_payment', FALSE); } } }