-
-
+
api_request_url( AdminController::GET_ORDER_TRANSACTIONS_ROUTE_SLUG );
@@ -86,10 +80,9 @@ function unzerRefreshData() {
if (data.transactions) {
let tHtml = '';
for (const transaction of data.transactions) {
- let color = transaction.status === 'error' ? '#cc0000' : '#000000';
- color = transaction.status === 'pending' ? '#bbb' : color;
+ const rowClass = transaction.status === 'error' ? 'unzer-row-error' : (transaction.status === 'pending' ? 'unzer-row-pending' : 'unzer-row-success');
tHtml += `
-
+
| ${transaction.time} |
${transaction.type} |
${transaction.id} |
@@ -101,24 +94,25 @@ function unzerRefreshData() {
document.getElementById('unzer-transactions-body').innerHTML = tHtml;
}
- document.getElementById('unzer-status-message').innerHTML = data.status === 'chargeback' ? 'CHARGEBACK!
' : '';
-
- let captureAction = '';
- if (data.remainingPlain && data.paymentMethod !== 'unzer_prepayment') {
- captureAction = ' ' +
- ''
+ const orderStatusMessageContainer = document.getElementById('unzer-status-message');
+ orderStatusMessageContainer.innerHTML = ''+data.status+'';
+ orderStatusMessageContainer.className = "unzer-status-"+data.status;
- }
- let amountHtml = `
-
| : | ${data.amount} |
- | : | ${data.charged} |
- | : | ${data.cancelled} |
- | : | ${data.remaining} |
- | ${captureAction} |
- `;
+ const totalsHtml = `
+ : ${data.amount}
+ : ${data.charged}
+ : ${data.cancelled}
+ : ${data.remaining}
+ `;
+ document.getElementById('unzer-totals-row').innerHTML = totalsHtml;
- document.getElementById('unzer-sums-body').innerHTML = amountHtml;
+ let captureHtml = '';
+ if (data.remainingPlain && data.paymentMethod !== 'unzer_prepayment' && data.status !== 'canceled') {
+ captureHtml = `
+ `;
+ }
+ document.getElementById('unzer-capture-row').innerHTML = captureHtml;
if (data.raw) {
document.getElementById('unzer-debug').innerHTML = data.raw;
}
@@ -132,6 +126,10 @@ function unzerRefreshData() {
unzerRefreshData();
function unzerCaptureOrder(orderId, amount, nonce) {
+ const btn = document.getElementById('unzer-capture-btn');
+ if (btn) {
+ btn.classList.add('is-loading');
+ }
const formData = new FormData();
formData.append('order_id', orderId);
formData.append('amount', amount);
@@ -143,13 +141,14 @@ function unzerCaptureOrder(orderId, amount, nonce) {
.then(data => {
if (data.error) {
alert(data.error);
+ if (btn) {
+ btn.classList.remove('is-loading');
+ }
}
unzerRefreshData();
- })
-
+ });
}
true ) );
-wp_add_inline_script( 'unzer_admin_webhook_management_js', $script );
-
+wp_add_inline_script( 'unzer_admin_webhook_management_js', $script );
\ No newline at end of file
diff --git a/includes/Main.php b/includes/Main.php
index 359d896..a2a6d3d 100755
--- a/includes/Main.php
+++ b/includes/Main.php
@@ -2,42 +2,41 @@
namespace UnzerPayments;
+use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
use UnzerPayments\Controllers\AccountController;
use UnzerPayments\Controllers\AdminController;
use UnzerPayments\Controllers\CheckoutController;
use UnzerPayments\Controllers\WebhookController;
use UnzerPayments\Gateways\AbstractGateway;
use UnzerPayments\Gateways\Alipay;
-use UnzerPayments\Gateways\ApplePay;
-use UnzerPayments\gateways\ApplePayV2;
+use UnzerPayments\Gateways\ApplePayV2;
use UnzerPayments\Gateways\Bancontact;
use UnzerPayments\Gateways\Card;
use UnzerPayments\Gateways\DirectDebit;
use UnzerPayments\Gateways\DirectDebitSecured;
use UnzerPayments\Gateways\Eps;
-use UnzerPayments\gateways\GooglePay;
+use UnzerPayments\Gateways\GooglePay;
use UnzerPayments\Gateways\Ideal;
use UnzerPayments\Gateways\Installment;
use UnzerPayments\Gateways\Invoice;
-use UnzerPayments\gateways\OpenBanking;
+use UnzerPayments\Gateways\Klarna;
+use UnzerPayments\Gateways\OpenBanking;
use UnzerPayments\Gateways\Paypal;
use UnzerPayments\Gateways\PostFinanceCard;
use UnzerPayments\Gateways\PostFinanceEfinance;
use UnzerPayments\Gateways\Prepayment;
use UnzerPayments\Gateways\Przelewy24;
-use UnzerPayments\Gateways\Sofort;
-use UnzerPayments\gateways\Twint;
+use UnzerPayments\Gateways\Twint;
use UnzerPayments\Gateways\WeChatPay;
-use UnzerPayments\SdkExtension\Resource\ApplePayCertificate;
-use UnzerPayments\SdkExtension\Resource\ApplePayPrivateKey;
-use UnzerPayments\SdkExtension\Services\AppleKeyService;
+use UnzerPayments\Gateways\Wero;
use UnzerPayments\Services\DashboardService;
use UnzerPayments\Services\OrderService;
-use UnzerPayments\Services\PaymentService;
+use WC_Payment_Gateway;
class Main {
+
public static $instance;
const ORDER_META_KEY_AUTHORIZATION_ID = 'unzer_authorization_id';
const ORDER_META_KEY_CHARGE_ID = 'unzer_charge_id';
@@ -54,7 +53,6 @@ class Main {
self::ORDER_META_KEY_PAYMENT_SHORT_ID,
self::ORDER_META_KEY_PAYMENT_INSTRUCTIONS,
self::ORDER_META_KEY_CANCELLATION_ID,
- self::ORDER_META_KEY_DATE_OF_BIRTH,
);
const USER_META_KEY_PAYMENT_INSTRUMENTS = 'payment_instruments';
@@ -82,13 +80,11 @@ public function registerEvents(): void {
add_action( 'woocommerce_api_' . AdminController::WEBHOOK_MANAGEMENT_ROUTE_SLUG, array( new AdminController(), 'webhookManagement' ) );
add_action( 'woocommerce_api_' . AdminController::KEY_VALIDATION_ROUTE_SLUG, array( new AdminController(), 'validateKeypair' ) );
add_action( 'woocommerce_api_' . AdminController::NOTIFICATION_SLUG, array( new AdminController(), 'handleNotification' ) );
- add_action( 'woocommerce_api_' . AdminController::APPLE_PAY_REMOVE_KEY_ROUTE_SLUG, array( new AdminController(), 'applePayRemoveKey' ) );
- add_action( 'woocommerce_api_' . AdminController::APPLE_PAY_VALIDATE_CREDENTIALS_ROUTE_SLUG, array( new AdminController(), 'applePayValidateCredentials' ) );
add_action( 'woocommerce_api_' . AbstractGateway::CONFIRMATION_ROUTE_SLUG, array( new CheckoutController(), 'confirm' ) );
add_action( 'woocommerce_api_' . WebhookController::WEBHOOK_ROUTE_SLUG, array( new WebhookController(), 'receiveWebhook' ) );
add_action( 'woocommerce_api_' . AccountController::DELETE_PAYMENT_INSTRUMENT_URL_SLUG, array( new AccountController(), 'deletePaymentInstrument' ) );
- add_action( 'woocommerce_api_' . CheckoutController::APPLE_PAY_MERCHANT_VALIDATION_ROUTE_SLUG, array( new CheckoutController(), 'validateApplePayMerchant' ) );
+ add_action( 'woocommerce_api_' . CheckoutController::GET_UNZER_CUSTOMER_SLUG, array( new CheckoutController(), 'getUnzerCustomerData' ) );
add_filter( 'plugin_action_links_' . plugin_basename( UNZER_PLUGIN_PATH . 'unzer-payments.php' ), array( $this, 'addPluginSettingsLink' ) );
add_action( 'add_meta_boxes', array( $this, 'addMetaBoxes' ), 40 );
add_action( 'woocommerce_settings_checkout', array( AdminController::class, 'renderGlobalSettingsStart' ) );
@@ -100,10 +96,11 @@ public function registerEvents(): void {
add_action( 'woocommerce_update_options_payment_gateways_unzer_card', array( $this, 'savePaymentMethodSettingsCard' ) );
add_action( 'woocommerce_update_options_payment_gateways_unzer_paypal', array( $this, 'savePaymentMethodSettingsPaypal' ) );
add_action( 'woocommerce_update_options_payment_gateways_unzer_direct_debit', array( $this, 'savePaymentMethodSettingsDirectDebit' ) );
- add_action( 'woocommerce_update_options_payment_gateways_unzer_apple_pay', array( $this, 'savePaymentMethodSettingsApplePay' ) );
add_action( 'woocommerce_update_options_payment_gateways_unzer_apple_pay_v2', array( $this, 'savePaymentMethodSettingsApplePayV2' ) );
add_action( 'woocommerce_update_options_checkout_unzer_general', array( $this, 'saveGeneralSettings' ) );
add_action( 'admin_notices', array( new DashboardService(), 'showNotifications' ) );
+ // add_action( 'woocommerce_blocks_loaded', array( $this, 'addCheckoutBlocks' ) );
+ add_action( 'before_woocommerce_pay_form', array( $this, 'orderPayPaymentMethod' ), 20, 4 );
add_action(
'admin_enqueue_scripts',
function () {
@@ -245,48 +242,6 @@ public function savePaymentMethodSettingsApplePayV2(): void {
( new DashboardService() )->addError( 'apple_pay_id_file' );
}
}
- public function savePaymentMethodSettingsApplePay(): void {
- if ( empty( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), 'woocommerce-settings' ) ) {
- return;
- }
- if ( ! empty( $_FILES['unzer_apple_pay_payment_processing_certificate']['tmp_name'] ) && ! empty( $_FILES['unzer_apple_pay_payment_processing_key']['tmp_name'] ) ) {
- $client = ( new PaymentService() )->getUnzerManager();
- $certificate = file_get_contents( sanitize_url( $_FILES['unzer_apple_pay_payment_processing_certificate']['tmp_name'] ) );
- $key = file_get_contents( sanitize_url( $_FILES['unzer_apple_pay_payment_processing_key']['tmp_name'] ) );
-
- if ( extension_loaded( 'openssl' ) && ! openssl_x509_parse( $certificate ) ) {
- throw new \Exception( 'Invalid Payment Processing certificate given' );
- }
-
- $privateKeyResource = new ApplePayPrivateKey();
- $privateKeyResource->setCertificate( $key );
- $client->getResourceService()->createResource( $privateKeyResource->setParentResource( $client ) );
- /** @var string $privateKeyId */
- $privateKeyId = $privateKeyResource->getId();
- update_option( 'unzer_apple_pay_payment_key_id', $privateKeyId );
- $certificateResource = new ApplePayCertificate();
- $certificateResource->setCertificate( $certificate );
- $certificateResource->setPrivateKey( $privateKeyId );
- $client->getResourceService()->createResource( $certificateResource->setParentResource( $client ) );
-
- $certificateService = new AppleKeyService( $client );
- $activateSuccess = $certificateService->activateCertificate( $certificateResource->getId() );
- if ( ! $activateSuccess ) {
- throw new \Exception( 'Could not activate Apple Pay certificate' );
- }
- update_option( 'unzer_apple_pay_payment_certificate_id', $certificateResource->getId() );
- }
-
- if ( ! empty( $_FILES['unzer_apple_pay_merchant_id_certificate']['tmp_name'] ) ) {
- $certificate = file_get_contents( sanitize_url( $_FILES['unzer_apple_pay_merchant_id_certificate']['tmp_name'] ) );
- update_option( 'unzer_apple_pay_merchant_id_certificate', $certificate );
- }
-
- if ( ! empty( $_FILES['unzer_apple_pay_merchant_id_key']['tmp_name'] ) ) {
- $certificate = file_get_contents( sanitize_url( $_FILES['unzer_apple_pay_merchant_id_key']['tmp_name'] ) );
- update_option( 'unzer_apple_pay_merchant_id_key', $certificate );
- }
- }
public function setMetaProtected( $protected, $meta_key, $meta_type ) {
if ( in_array( $meta_key, self::ORDER_META_KEYS ) ) {
@@ -397,10 +352,7 @@ public function getPaymentGateways(): array {
WeChatPay::GATEWAY_ID => WeChatPay::class,
Alipay::GATEWAY_ID => Alipay::class,
Eps::GATEWAY_ID => Eps::class,
- // Giropay::GATEWAY_ID => Giropay::class,
- Sofort::GATEWAY_ID => Sofort::class,
- // Klarna::GATEWAY_ID => Klarna::class,
- // Pis::GATEWAY_ID => Pis::class,
+ Klarna::GATEWAY_ID => Klarna::class,
DirectDebit::GATEWAY_ID => DirectDebit::class,
DirectDebitSecured::GATEWAY_ID => DirectDebitSecured::class,
Invoice::GATEWAY_ID => Invoice::class,
@@ -409,11 +361,11 @@ public function getPaymentGateways(): array {
Ideal::GATEWAY_ID => Ideal::class,
PostFinanceEfinance::GATEWAY_ID => PostFinanceEfinance::class,
PostFinanceCard::GATEWAY_ID => PostFinanceCard::class,
- ApplePay::GATEWAY_ID => ApplePay::class,
ApplePayV2::GATEWAY_ID => ApplePayV2::class,
GooglePay::GATEWAY_ID => GooglePay::class,
Twint::GATEWAY_ID => Twint::class,
OpenBanking::GATEWAY_ID => OpenBanking::class,
+ Wero::GATEWAY_ID => Wero::class,
);
}
@@ -424,4 +376,39 @@ public function getPaymentGateway( $key ): ?AbstractGateway {
}
return null;
}
+
+ public function addCheckoutBlocks() {
+ if ( class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
+ add_action(
+ 'woocommerce_blocks_payment_method_type_registration',
+ function ( PaymentMethodRegistry $payment_method_registry ) {
+ foreach ( $this->getPaymentGateways() as $gatewayClass ) {
+ if ( defined( $gatewayClass . '::BLOCK_CLASS' ) ) {
+ $blockClass = constant( $gatewayClass . '::BLOCK_CLASS' );
+ if ( class_exists( $blockClass ) ) {
+ $payment_method_registry->register( new $blockClass() );
+ }
+ }
+ }
+ }
+ );
+ }
+ }
+
+ public function orderPayPaymentMethod( $order, $order_button_text, $available_gateways ) {
+ $paymentMethod = (string) $order->get_payment_method();
+ if ( AbstractGateway::isUnzerPaymentMethod( $paymentMethod ) ) {
+ $isSelectedGatewayActive = false;
+ /** @var WC_Payment_Gateway $gateway */
+ foreach ( $available_gateways as $gateway ) {
+ if ( $gateway->id === $paymentMethod ) {
+ $isSelectedGatewayActive = true;
+ break;
+ }
+ }
+ foreach ( $available_gateways as $gateway ) {
+ $gateway->chosen = ( $gateway->id === $paymentMethod );
+ }
+ }
+ }
}
diff --git a/includes/Util.php b/includes/Util.php
index 56af8a8..29a7c0a 100644
--- a/includes/Util.php
+++ b/includes/Util.php
@@ -51,15 +51,7 @@ public static function getNonceField( $doPrint = true, string $action = '' ) {
}
}
- public static function getDobFromPost(): ?string {
- return self::getNonceCheckedPostValue( 'unzer-dob' );
- }
-
- public static function getCompanyTypeFromPost(): ?string {
- return self::getNonceCheckedPostValue( 'unzer-invoice-company-type' );
- }
-
- public static function getNonceCheckedPostValue( string $key ): ?string {
+ public static function getNonceCheckedPostValue( string $key, $skipSanitize = false ): ?string {
if ( ! empty( $_POST[ $key ] ) ) {
// our own nonce:
if ( isset( $_POST[ self::NONCE_NAME ] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST[ self::NONCE_NAME ] ) ), self::NONCE_NAME ) ) {
@@ -67,12 +59,24 @@ public static function getNonceCheckedPostValue( string $key ): ?string {
}
// woocommerce nonce:
if ( isset( $_POST['security'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['security'] ) ), 'update-order-review' ) ) {
- return sanitize_text_field( wp_unslash( $_POST[ $key ] ) );
+ $value = wp_unslash( $_POST[ $key ] );
+ return $skipSanitize ? $value : sanitize_text_field( $value );
}
}
return null;
}
+ public static function getNonceCheckedBillingData(): array {
+ $postData = self::getNonceCheckedPostValue( 'post_data', true );
+ if ( ! empty( $postData ) ) {
+ parse_str( $postData, $params );
+ $params = array_map( 'sanitize_text_field', $params );
+ return $params;
+ }
+ return array();
+ }
+
+
public static function escape_array_html( $data ) {
if ( is_array( $data ) ) {
foreach ( $data as $key => $value ) {
diff --git a/includes/controllers/AccountController.php b/includes/controllers/AccountController.php
old mode 100755
new mode 100644
index 91878f6..4e50701
--- a/includes/controllers/AccountController.php
+++ b/includes/controllers/AccountController.php
@@ -33,12 +33,15 @@ public function deletePaymentInstrument() {
}
public function accountPaymentInstruments() {
- $gateways = array(
+ $gateways = array(
Card::class,
Paypal::class,
DirectDebit::class,
);
- $html = '';
+ $html = '';
+ $deleteUrl = WC()->api_request_url( self::DELETE_PAYMENT_INSTRUMENT_URL_SLUG );
+ $nonce = Util::getNonce();
+
foreach ( $gateways as $gateway ) {
/** @var Card|Paypal|DirectDebit $gatewayObject */
$gatewayObject = new $gateway();
@@ -46,23 +49,31 @@ public function accountPaymentInstruments() {
if ( $savedInstruments && $gatewayObject->isSaveInstruments() ) {
$html .= '
' . $gatewayObject->get_title() . '
';
}
}
if ( $html ) {
- $html = '
' . __( 'Your saved payment means', 'unzer-payments' ) . '
' . $html;
+ wp_enqueue_script( 'unzer_account_js', UNZER_PLUGIN_URL . '/assets/js/account.js', array(), UNZER_VERSION, array( 'in_footer' => true ) );
+ $html = '
' . esc_html__( 'Your saved payment means', 'unzer-payments' ) . '
' . $html;
}
- echo wp_kses_post( $html );
+ echo wp_kses(
+ $html,
+ array(
+ 'h2' => array(),
+ 'div' => array( 'class' => array() ),
+ 'b' => array(),
+ 'ul' => array(),
+ 'li' => array(),
+ 'a' => array(
+ 'href' => array(),
+ 'class' => array(),
+ 'data-instrument-id' => array(),
+ 'data-delete-url' => array(),
+ 'data-nonce' => array(),
+ ),
+ )
+ );
}
}
diff --git a/includes/controllers/AdminController.php b/includes/controllers/AdminController.php
old mode 100755
new mode 100644
index fc3a578..ca5e850
--- a/includes/controllers/AdminController.php
+++ b/includes/controllers/AdminController.php
@@ -3,13 +3,10 @@
namespace UnzerPayments\Controllers;
use Exception;
-use UnzerPayments\Gateways\ApplePay;
use UnzerPayments\Gateways\DirectDebitSecured;
use UnzerPayments\Gateways\Installment;
use UnzerPayments\Gateways\Invoice;
use UnzerPayments\Main;
-use UnzerPayments\SdkExtension\Resource\ApplePayCertificate;
-use UnzerPayments\SdkExtension\Resource\ApplePayPrivateKey;
use UnzerPayments\Services\DashboardService;
use UnzerPayments\Services\PaymentService;
use UnzerPayments\Services\WebhookManagementService;
@@ -23,13 +20,12 @@
class AdminController {
- const GET_ORDER_TRANSACTIONS_ROUTE_SLUG = 'admin_unzer_get_order_transactions';
- const CHARGE_ROUTE_SLUG = 'admin_unzer_charge';
- const WEBHOOK_MANAGEMENT_ROUTE_SLUG = 'admin_unzer_webhooks';
- const KEY_VALIDATION_ROUTE_SLUG = 'admin_unzer_key_validation';
- const NOTIFICATION_SLUG = 'admin_unzer_notification';
- const APPLE_PAY_REMOVE_KEY_ROUTE_SLUG = 'admin_unzer_apple_pay_remove_key';
- const APPLE_PAY_VALIDATE_CREDENTIALS_ROUTE_SLUG = 'admin_unzer_apple_pay_validate_credentials';
+
+ const GET_ORDER_TRANSACTIONS_ROUTE_SLUG = 'admin_unzer_get_order_transactions';
+ const CHARGE_ROUTE_SLUG = 'admin_unzer_charge';
+ const WEBHOOK_MANAGEMENT_ROUTE_SLUG = 'admin_unzer_webhooks';
+ const KEY_VALIDATION_ROUTE_SLUG = 'admin_unzer_key_validation';
+ const NOTIFICATION_SLUG = 'admin_unzer_notification';
public function getOrderTransactions() {
try {
@@ -241,126 +237,6 @@ public function validateKeypair() {
}
}
- public function applePayValidateCredentials() {
- $paymentGateway = new ApplePay();
- $status = array(
- 'unzer_apple_pay_payment_certificate_id' => 0,
- 'unzer_apple_pay_payment_key_id' => 0,
- 'unzer_apple_pay_merchant_id_certificate' => 0,
- 'unzer_apple_pay_merchant_id_key' => 0,
- );
- $messages = array(
- 'unzer_apple_pay_payment_certificate_id' => __( 'invalid', 'unzer-payments' ),
- 'unzer_apple_pay_payment_key_id' => __( 'invalid', 'unzer-payments' ),
- 'unzer_apple_pay_merchant_id_certificate' => __( 'invalid', 'unzer-payments' ),
- 'unzer_apple_pay_merchant_id_key' => __( 'invalid', 'unzer-payments' ),
- );
-
- $client = ( new PaymentService() )->getUnzerManager();
-
- if ( get_option( 'unzer_apple_pay_payment_certificate_id' ) ) {
- try {
- $certificateResource = new ApplePayCertificate();
- $certificateResource->setId( get_option( 'unzer_apple_pay_payment_certificate_id' ) );
- $certificateResource->setParentResource( $client );
- $submittedCertificate = $client->getResourceService()->fetchResource( $certificateResource );
- if ( $submittedCertificate->getId() ) {
- if ( $submittedCertificate->getActive() === false ) {
- throw new Exception( __( 'The certificate is not active', 'unzer-payments' ) );
- }
- $status['unzer_apple_pay_payment_certificate_id'] = 1;
- $messages['unzer_apple_pay_payment_certificate_id'] = __( 'valid', 'unzer-payments' );
- }
- } catch ( Exception $e ) {
- $messages['unzer_apple_pay_payment_certificate_id'] = $e->getMessage();
- }
- }
- //
- // if ( get_option( 'unzer_apple_pay_payment_key_id' ) ) {
- // try {
- // $keyResource = new ApplePayPrivateKey();
- // $keyResource->setId( get_option( 'unzer_apple_pay_payment_key_id' ) );
- // $keyResource->setParentResource( $client );
- // $submittedKey = $client->getResourceService()->fetchResource( $keyResource );
- //
- // if ( $submittedKey->getId() ) {
- // if ( ! empty( $submittedCertificate ) && $submittedKey->getParentResource()->getKey() !== $submittedCertificate->getParentResource()->getKey() ) {
- // throw new Exception( __( 'The certificate and the key do not match', 'unzer-payments' ) );
- // }
- // $status['unzer_apple_pay_payment_key_id'] = 1;
- // $messages['unzer_apple_pay_payment_key_id'] = __( 'valid', 'unzer-payments' );
- // }
- // } catch ( Exception $e ) {
- // $messages['unzer_apple_pay_payment_key_id'] = $e->getMessage();
- // }
- // }
-
- if ( get_option( 'unzer_apple_pay_merchant_id_certificate' ) ) {
- try {
- $certificate = get_option( 'unzer_apple_pay_merchant_id_certificate' );
- if ( extension_loaded( 'openssl' ) ) {
- $certificateData = openssl_x509_parse( $certificate );
- if ( ! is_array( $certificateData ) ) {
- throw new Exception( __( 'Unable to read certificate', 'unzer-payments' ) );
- }
- if ( $certificateData['subject']['UID'] !== $paymentGateway->get_option( 'merchant_id' ) ) {
- throw new Exception( __( 'Certificate does not match merchant id: ', 'unzer-payments' ) . $certificateData['subject']['UID'] );
- }
- } elseif ( ! str_starts_with( $certificate, '-----BEGIN CERTIFICATE-----' ) ) {
- throw new Exception( __( 'Not a valid certificate', 'unzer-payments' ) );
- }
- $status['unzer_apple_pay_merchant_id_certificate'] = 1;
- $messages['unzer_apple_pay_merchant_id_certificate'] = __( 'valid', 'unzer-payments' );
- } catch ( Exception $e ) {
- $messages['unzer_apple_pay_merchant_id_certificate'] = $e->getMessage();
- }
- }
-
- if ( get_option( 'unzer_apple_pay_merchant_id_key' ) ) {
- try {
- $key = get_option( 'unzer_apple_pay_merchant_id_key' );
- if ( extension_loaded( 'openssl' ) ) {
- $keyIsValid = openssl_x509_check_private_key( $certificate, $key );
- if ( ! $keyIsValid ) {
- throw new Exception( __( 'Key does not match certificate', 'unzer-payments' ) );
- }
- } elseif ( ! str_starts_with( $certificate, '-----BEGIN PRIVATE KEY-----' ) ) {
- throw new Exception( __( 'Not a valid private key', 'unzer-payments' ) );
- }
- $status['unzer_apple_pay_merchant_id_key'] = 1;
- $messages['unzer_apple_pay_merchant_id_key'] = __( 'valid', 'unzer-payments' );
- } catch ( Exception $e ) {
- $messages['unzer_apple_pay_merchant_id_key'] = $e->getMessage();
- }
- }
- $this->renderJson(
- array(
- 'status' => $status,
- 'messages' => $messages,
- )
- );
- }
-
- public function applePayRemoveKey() {
- $key = Util::getNonceCheckedPostValue( 'key' );
- if ( ! empty( $key ) ) {
- $key = 'unzer_apple_pay_' . $key;
- if ( get_option( $key ) ) {
- delete_option( $key );
- $this->renderJson(
- array(
- 'success' => 1,
- )
- );
- }
- }
- $this->renderJson(
- array(
- 'success' => 0,
- )
- );
- }
-
public static function renderTransactionTable( $postOrOrderObject ) {
$order = ( $postOrOrderObject instanceof WP_Post ) ? wc_get_order( $postOrOrderObject->ID ) : $postOrOrderObject;
if ( ! $order || ! ( $order instanceof \WC_Order ) ) {
diff --git a/includes/controllers/CheckoutController.php b/includes/controllers/CheckoutController.php
old mode 100755
new mode 100644
index 0fa0382..61b8240
--- a/includes/controllers/CheckoutController.php
+++ b/includes/controllers/CheckoutController.php
@@ -3,22 +3,19 @@
namespace UnzerPayments\Controllers;
use Exception;
-use UnzerPayments\Gateways\ApplePay;
-use UnzerPayments\Gateways\Prepayment;
+use UnzerPayments\Gateways\AbstractGateway;
use UnzerPayments\Main;
+use UnzerPayments\Services\CustomerService;
use UnzerPayments\Services\LogService;
use UnzerPayments\Services\OrderService;
use UnzerPayments\Services\PaymentService;
use UnzerPayments\Util;
-use UnzerSDK\Adapter\ApplepayAdapter;
use UnzerSDK\Constants\PaymentState;
-use UnzerSDK\Resources\ExternalResources\ApplepaySession;
use WC_Order;
class CheckoutController {
-
- const APPLE_PAY_MERCHANT_VALIDATION_ROUTE_SLUG = 'unzer_apple_pay_merchant_validation';
+ const GET_UNZER_CUSTOMER_SLUG = 'get-unzer-customer';
public function confirm() {
$logger = ( new LogService() );
@@ -29,6 +26,14 @@ public function confirm() {
$orderId = (int) WC()->session->get( 'unzer_confirm_order_id' );
WC()->session->set( 'unzer_confirm_order_id', null );
}
+ if ( empty( $orderId ) ) {
+ $logger->debug( 'order id from store_api_draft_order' );
+ $orderId = (int) WC()->session->get( 'store_api_draft_order' );
+ }
+ if ( empty( $orderId ) ) {
+ $logger->debug( 'order id from get query' );
+ $orderId = (int) ( $_GET['unzer_confirm_order_id'] ?? 0 );
+ }
if ( empty( $orderId ) ) {
$logger->error( 'empty order id for confirmation endpoint' );
wp_redirect( wc_get_checkout_url() );
@@ -38,6 +43,7 @@ public function confirm() {
$unzerPluginManager = Main::getInstance();
$paymentGateway = $unzerPluginManager->getPaymentGateway( $order->get_payment_method() );
if ( ! $paymentGateway ) {
+ $order->update_status( 'failed' );
$logger->error( 'payment method unknown', $order->get_payment_method() );
wc_add_notice( __( 'Payment error', 'unzer-payments' ), 'error' );
wp_redirect( wc_get_checkout_url() );
@@ -47,6 +53,7 @@ public function confirm() {
$transaction = $paymentService->getChargeOrAuthorizationFromOrder( $orderId, $paymentGateway );
if ( ! $transaction ) {
+ $order->update_status( 'failed' );
$paymentService->removeTransactionMetaData( $orderId );
$logger->error( 'no authorization/charge found', array( 'order' => $orderId ) );
wc_add_notice( __( 'Payment error', 'unzer-payments' ), 'error' );
@@ -64,12 +71,13 @@ public function confirm() {
'reason' => $transaction->getMessage()->getMerchant(),
)
);
+ $order->update_status( 'failed' );
wc_add_notice( __( 'Payment cancelled', 'unzer-payments' ), 'error' );
wp_redirect( wc_get_checkout_url() );
die;
}
- if ( method_exists( $paymentGateway, 'isSaveInstruments' ) ) {
+ if ( method_exists( $paymentGateway, 'maybeSavePaymentInstrument' ) ) {
if ( WC()->session->get( 'save_payment_instrument' ) ) {
$paymentGateway->maybeSavePaymentInstrument( $transaction->getPayment()->getPaymentType()->getId() );
}
@@ -77,6 +85,7 @@ public function confirm() {
$orderService = new OrderService();
try {
$orderService->processPaymentStatus( $transaction, $order );
+ self::clearSessionData();
wp_redirect( $order->get_checkout_order_received_url() );
} catch ( Exception $e ) {
$logger->error(
@@ -87,6 +96,7 @@ public function confirm() {
'exception' => $e->getMessage(),
)
);
+ $order->update_status( 'failed' );
wc_add_notice( __( 'Payment error', 'unzer-payments' ), 'error' );
wp_redirect( wc_get_checkout_url() );
}
@@ -94,61 +104,43 @@ public function confirm() {
die;
}
+ public function getUnzerCustomerData() {
+ $paymentMethodGatewayId = Util::getNonceCheckedPostValue( 'payment_method' );
+ $cartData = json_decode( Util::getNonceCheckedPostValue( 'data' ), true );
+ $paymentMethodGateway = Main::getInstance()->getPaymentGateway( $paymentMethodGatewayId );
+ $billingData = array();
+ foreach ( $cartData['billingAddress'] as $k => $v ) {
+ $billingData[ 'billing_' . $k ] = $v;
+ }
+ $unzerCustomer = ( new CustomerService() )->getCustomerFromData( $paymentMethodGateway, $billingData );
+
+ $paymentService = new PaymentService();
+ $publicKey = $paymentService->getPublicKey( $paymentMethodGateway, ! empty( $billingData['billing_company'] ), $cartData['totals']['currency_code'] );
+
+ $this->renderJson(
+ array(
+ 'customer' => $unzerCustomer->expose(),
+ 'publicKey' => $publicKey,
+ )
+ );
+ }
+
/**
* @param WC_Order $order
* @return void
*/
public static function checkoutSuccess( $order ) {
+ self::clearSessionData();
( new OrderService() )->printPaymentInstructionsHtml( $order );
}
- public function validateApplePayMerchant() {
- $applePayGateway = new ApplePay();
- $applePaySession = new ApplepaySession(
- $applePayGateway->get_option( 'merchant_id' ),
- get_bloginfo( 'name' ),
- isset( $_SERVER['HTTP_HOST'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : get_bloginfo( 'url' ),
- );
- $appleAdapter = new ApplepayAdapter();
-
- $certificateTempPath = tempnam( sys_get_temp_dir(), 'WpUnzerPayments' );
- $keyTempPath = tempnam( sys_get_temp_dir(), 'WpUnzerPayments' );
-
- if ( ! $certificateTempPath || ! $keyTempPath ) {
- throw new Exception( 'Error on temporary file creation' );
- }
-
- file_put_contents( $certificateTempPath, get_option( 'unzer_apple_pay_merchant_id_certificate' ) );
- file_put_contents( $keyTempPath, get_option( 'unzer_apple_pay_merchant_id_key' ) );
-
- try {
- $appleAdapter->init( $certificateTempPath, $keyTempPath );
- $merchantValidationUrl = urldecode( Util::getNonceCheckedPostValue( 'validation_url' ) );
- try {
- $validationResponse = $appleAdapter->validateApplePayMerchant(
- $merchantValidationUrl,
- $applePaySession
- );
- ( new LogService() )->debug( 'apple pay validation response', array( 'response' => $validationResponse ) );
- $this->renderJson( array( 'response' => $validationResponse ) );
- } catch ( Exception $e ) {
- ( new LogService() )->error(
- 'merchant validation failed',
- array(
- 'error' => $e->getMessage(),
- 'merchantValidationUrl' => $merchantValidationUrl,
- )
- );
- }
- } finally {
- wp_delete_file( $keyTempPath );
- wp_delete_file( $certificateTempPath );
- }
- }
-
protected function renderJson( array $data ) {
header( 'Content-Type: application/json' );
echo wp_json_encode( Util::escape_array_html( $data ) );
die;
}
+
+ protected static function clearSessionData() {
+ setcookie( CustomerService::SESSION_KEY_USER_ID, '', time() - 3600, COOKIEPATH, COOKIE_DOMAIN );
+ }
}
diff --git a/includes/controllers/WebhookController.php b/includes/controllers/WebhookController.php
old mode 100755
new mode 100644
diff --git a/includes/gateways/AbstractGateway.php b/includes/gateways/AbstractGateway.php
old mode 100755
new mode 100644
index 41faea7..ce460bd
--- a/includes/gateways/AbstractGateway.php
+++ b/includes/gateways/AbstractGateway.php
@@ -2,11 +2,9 @@
namespace UnzerPayments\Gateways;
-use DateTime;
-use Exception;
use UnzerPayments\Controllers\AdminController;
-use UnzerPayments\Controllers\CheckoutController;
use UnzerPayments\Main;
+use UnzerPayments\Services\CustomerService;
use UnzerPayments\Services\LogService;
use UnzerPayments\Services\PaymentService;
use UnzerPayments\Util;
@@ -24,6 +22,58 @@ abstract class AbstractGateway extends WC_Payment_Gateway {
+ const ALLOWED_HTML = array(
+ 'unzer-payment' => array(
+ 'id' => true,
+ 'class' => true,
+ 'locale' => true,
+ 'publicKey' => true,
+ 'publickey' => true,
+ 'data-customer' => true,
+ 'disableCTP' => true,
+ 'disablectp' => true,
+ ),
+ 'unzer-checkout' => array(
+ 'id' => true,
+ 'class' => true,
+ ),
+ 'unzer-card' => array(
+ 'id' => true,
+ 'class' => true,
+ ),
+ 'unzer-apple-pay' => array(
+ 'id' => true,
+ 'class' => true,
+ ),
+ 'unzer-google-pay' => array(
+ 'id' => true,
+ 'class' => true,
+ ),
+ 'unzer-sepa-direct-debit' => array(
+ 'id' => true,
+ 'class' => true,
+ ),
+ 'unzer-paylater-direct-debit' => array(
+ 'id' => true,
+ 'class' => true,
+ ),
+ 'unzer-paylater-installment' => array(
+ 'id' => true,
+ 'class' => true,
+ ),
+ 'unzer-paylater-invoice' => array(
+ 'id' => true,
+ 'class' => true,
+ ),
+ 'unzer-open-banking' => array(
+ 'id' => true,
+ 'class' => true,
+ ),
+ 'template' => array(
+ 'id' => true,
+ 'class' => true,
+ ),
+ );
const CONFIRMATION_ROUTE_SLUG = 'unzer-confirm';
const TRANSACTION_TYPE_AUTHORIZE = 'authorize';
@@ -42,8 +92,10 @@ abstract class AbstractGateway extends WC_Payment_Gateway {
/**
* @var null|array
*/
- public $allowedCurrencies = null;
- public $allowedCountries = null;
+ public $allowedCurrencies = null;
+ public $allowedCountries = null;
+ public $isAllowedForB2B = null;
+ public $allowedCountryCurrencySets = null;
public function __construct() {
$this->logger = new LogService();
@@ -60,6 +112,12 @@ public function __construct() {
add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
}
+ protected function get_allowed_html_tags() {
+ $response = array_merge( wp_kses_allowed_html( 'post' ), self::ALLOWED_HTML );
+ $response['input']['checked'] = true;
+ return $response;
+ }
+
public function payment_scripts() {
if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
return;
@@ -97,17 +155,81 @@ public function is_enabled() {
return $this->enabled === 'yes';
}
+ protected function get_billing_data_from_post(): array {
+ $postData = Util::getNonceCheckedPostValue( 'post_data' );
+ if ( ! empty( $postData ) ) {
+ parse_str( $postData, $params );
+ return $params;
+ }
+ return array();
+ }
+
+ protected function get_company_from_post() {
+ $company = Util::getNonceCheckedPostValue( 'company' );
+ if ( ! empty( $company ) ) {
+ return $company;
+ }
+
+ $postData = Util::getNonceCheckedPostValue( 'post_data' );
+ if ( ! empty( $postData ) ) {
+ parse_str( $postData, $params );
+ if ( ! empty( $params['billing_company'] ) ) {
+ return $params['billing_company'];
+ }
+ }
+ return '';
+ }
+
+ protected function getCurrentCountry() {
+ $country = Util::getNonceCheckedPostValue( 'country' );
+ if ( ! empty( $country ) ) {
+ return $country;
+ }
+ if ( WC()->session !== null ) {
+ $customer = WC()->session->get( 'customer' );
+ if ( ! empty( $customer['country'] ) ) {
+ return $customer['country'];
+ }
+ }
+ return null;
+ }
+
public function is_available() {
$isAvailable = parent::is_available();
if ( $isAvailable && ! empty( $this->allowedCurrencies ) ) {
$isAvailable = in_array( get_woocommerce_currency(), $this->allowedCurrencies );
}
if ( $isAvailable && ! empty( $this->allowedCountries ) ) {
- $country = Util::getNonceCheckedPostValue( 'country' );
+ $country = $this->getCurrentCountry();
if ( ! empty( $country ) && ! in_array( $country, $this->allowedCountries ) ) {
$isAvailable = false;
}
}
+ if ( $isAvailable && $this->isAllowedForB2B === false ) {
+ $company = $this->get_company_from_post();
+ if ( ! empty( $company ) ) {
+ $isAvailable = false;
+ }
+ }
+
+ if ( $isAvailable && ! empty( $this->allowedCountryCurrencySets ) ) {
+ $country = $this->getCurrentCountry();
+ $currency = get_woocommerce_currency();
+ $isFound = false;
+ foreach ( $this->allowedCountryCurrencySets as $allowedCountryCurrencySet ) {
+ if ( ! empty( $country ) && $allowedCountryCurrencySet['country'] !== $country ) {
+ continue;
+ }
+ if ( $allowedCountryCurrencySet['currency'] !== $currency ) {
+ continue;
+ }
+ $isFound = true;
+ break;
+ }
+ if ( ! $isFound ) {
+ $isAvailable = false;
+ }
+ }
return $isAvailable;
}
@@ -123,12 +245,17 @@ public function process_payment( $order_id ) {
'result' => 'success',
);
$charge = ( new PaymentService() )->performChargeForOrder( $order_id, $this, $this->paymentTypeResource );
+ $this->before_payment_redirect( $order_id );
if ( $charge->getPayment()->getRedirectUrl() ) {
$return['redirect'] = $charge->getPayment()->getRedirectUrl();
}
return $return;
}
+ protected function before_payment_redirect( $order_id ) {
+ WC()->session->set( 'unzer_confirm_order_id', $order_id );
+ }
+
public function process_refund( $order_id, $amount = null, $reason = '' ) {
try {
$paymentService = new PaymentService();
@@ -163,8 +290,13 @@ public function process_refund_on_payment( $order_id, $amount = null, $reason =
}
}
- public function get_confirm_url(): string {
- return WC()->api_request_url( static::CONFIRMATION_ROUTE_SLUG );
+ public function get_confirm_url( $order_id = null ): string {
+ $url = WC()->api_request_url( static::CONFIRMATION_ROUTE_SLUG );
+ if ( $order_id !== null ) {
+ $separator = strpos( $url, '?' ) === false ? '?' : '&';
+ $url .= $separator . 'unzer_confirm_order_id=' . $order_id;
+ }
+ return $url;
}
public function admin_options() {
@@ -286,48 +418,19 @@ protected function set_order_transaction_number( $order, $unzerPaymentId ) {
$order->save();
}
- /**
- * @param WC_Order $order
- * @return void
- * @throws Exception
- */
- protected function handleDateOfBirth( $order, $dateOfBirth ) {
- $birthDate = new DateTime( $dateOfBirth );
- $maxDate = new DateTime( '-18 years' );
- $minDate = new DateTime( '-120 years' );
- if ( $birthDate >= $maxDate ) {
- throw new Exception( esc_html__( 'You have to be at least 18 years old for this payment method', 'unzer-payments' ) );
- }
- if ( $birthDate < $minDate ) {
- throw new Exception( esc_html__( 'Please check your date of birth', 'unzer-payments' ) );
- }
- $order->update_meta_data( Main::ORDER_META_KEY_DATE_OF_BIRTH, gmdate( 'Y-m-d', strtotime( $dateOfBirth ) ) );
- $order->save_meta_data();
-
- $user = wp_get_current_user();
- if ( $user->ID ) {
- update_user_meta( $user->ID, Main::ORDER_META_KEY_DATE_OF_BIRTH, gmdate( 'Y-m-d', strtotime( $dateOfBirth ) ) );
- }
+ public function get_checkout_customer_json() {
+ global $wp;
+ $orderId = $this->isOrderPay() ? (int) $wp->query_vars['order-pay'] : null;
+ $customer = ( new CustomerService() )->getCustomerFromSession( $this, $orderId );
+ return $customer !== null ? json_encode( $customer->expose() ) : '';
}
- protected function getUserBirthDate(): string {
- $dob = '';
- $user = wp_get_current_user();
- if ( $user->ID ) {
- $dobFromUser = get_user_meta( $user->ID, Main::ORDER_META_KEY_DATE_OF_BIRTH, true );
- if ( $dobFromUser ) {
- $dob = gmdate( 'Y-m-d', strtotime( $dobFromUser ) );
- }
- }
- return $dob;
+ protected function get_checkout_customer_json_encoded() {
+ return base64_encode( $this->get_checkout_customer_json() );
}
protected function addCheckoutAssets() {
- wp_enqueue_script( 'unzer_js', 'https://static.unzer.com/v1/unzer.js', array(), UNZER_VERSION, array( 'in_footer' => false ) );
- wp_enqueue_style( 'unzer_css', 'https://static.unzer.com/v1/unzer.css', array(), UNZER_VERSION );
- wp_enqueue_style( 'woocommerce_unzer_css', UNZER_PLUGIN_URL . '/assets/css/checkout.css', array(), UNZER_VERSION );
- wp_register_script( 'woocommerce_unzer', UNZER_PLUGIN_URL . '/assets/js/checkout.js', array( 'unzer_js', 'jquery' ), UNZER_VERSION, array( 'in_footer' => false ) );
-
+ global $wp;
// TODO replace when minimum WP version is 6.5 (wp_enqueue_script_module)
add_filter(
'script_loader_tag',
@@ -343,8 +446,16 @@ function ( $tag, $handle, $src ) {
10,
3
);
- wp_enqueue_script( 'unzer_ui_v2_js', 'https://static-v2.unzer.com/v2/ui-components/index.js', array(), UNZER_VERSION, array( 'in_footer' => true ) );
+ wp_enqueue_script( 'unzer_ui_v2_js', 'https://static.test.unzer.com/v2/ui-components/index.js', array(), UNZER_VERSION, array( 'in_footer' => true ) ); // https://static-v2.unzer.com/v2/ui-components/index.js
+ wp_enqueue_style( 'woocommerce_unzer_css', UNZER_PLUGIN_URL . '/assets/css/checkout.css', array(), UNZER_VERSION );
+ if ( ( $this instanceof GooglePay ) && empty( $this->get_description() ) ) {
+ wp_add_inline_style( 'woocommerce_unzer_css', '.payment_box.payment_method_unzer_google_pay{display:none !important;}' );
+ } elseif ( ( $this instanceof ApplePayV2 ) && empty( $this->get_description() ) ) {
+ wp_add_inline_style( 'woocommerce_unzer_css', '.payment_box.payment_method_unzer_apple_pay_v2{display:none !important;}' );
+ }
+
+ wp_register_script( 'woocommerce_unzer', UNZER_PLUGIN_URL . '/assets/js/checkout.js', array( 'jquery' ), UNZER_VERSION, array( 'in_footer' => false ) );
// for separate api keys
$paylaterGateway = new Invoice();
$installmentGateway = new Installment();
@@ -367,7 +478,7 @@ function ( $tag, $handle, $src ) {
'locale' => get_locale(),
'store_name' => get_bloginfo( 'name' ),
'store_country' => strtoupper( substr( get_option( 'woocommerce_default_country' ), 0, 2 ) ),
- 'apple_pay_merchant_validation_url' => WC()->api_request_url( CheckoutController::APPLE_PAY_MERCHANT_VALIDATION_ROUTE_SLUG ),
+ 'is_order_pay' => self::isOrderPay() ? 'true' : 'false',
'currency' => get_woocommerce_currency(),
'google_pay_options' => array(
'gatewayMerchantId' => $googlePayGateway->get_option( 'channel_id' ),
@@ -392,17 +503,19 @@ function ( $tag, $handle, $src ) {
'woocommerce_unzer',
'unzer_i18n',
array(
- 'errorDob' => __( 'Please enter your date of birth', 'unzer-payments' ),
- 'errorCompanyType' => __( 'Please enter your company type', 'unzer-payments' ),
'errorSepaMandate' => __( 'Please accept the SEPA mandate', 'unzer-payments' ),
)
);
wp_enqueue_script( 'woocommerce_unzer' );
}
- public static function addRiskDataToAuthorization( Authorization $authorization ) {
+ public static function isOrderPay() {
+ global $wp;
+ return ! empty( $wp->query_vars['order-pay'] );
+ }
+
+ public static function addRiskDataToAuthorization( Authorization $authorization, ?string $riskId ) {
$riskData = new RiskData();
- $riskData->setThreatMetrixId( WC()->session->get( 'unzerThreatMetrixId' ) );
if ( is_user_logged_in() ) {
/** @var \WP_User $user */
$user = wp_get_current_user();
@@ -412,28 +525,13 @@ public static function addRiskDataToAuthorization( Authorization $authorization
} else {
$riskData->setRegistrationLevel( 0 );
}
+ if ( $riskId !== null ) {
+ $riskData->setThreatMetrixId( $riskId );
+ }
$authorization->setRiskData( $riskData );
}
- public static function removeRiskDataFromSession() {
- WC()->session->set( 'unzerThreatMetrixId', null );
- }
-
-
- protected function threatmetrix_payment_scripts() {
- if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
- return;
- }
-
- if ( ! $this->is_enabled() ) {
- return;
- }
-
- if ( empty( WC()->session->get( 'unzerThreatMetrixId' ) ) ) {
- WC()->session->set( 'unzerThreatMetrixId', uniqid( 'unzer_tm_' ) );
- }
- wp_enqueue_script( 'unzer_threat_metrix_js', 'https://h.online-metrix.net/fp/tags.js?org_id=363t8kgq&session_id=' . WC()->session->get( 'unzerThreatMetrixId' ), array(), UNZER_VERSION, array( 'in_footer' => false ) );
-
- $this->addCheckoutAssets();
+ public static function isUnzerPaymentMethod( string $paymentMethodId ) {
+ return substr( $paymentMethodId, 0, 6 ) === 'unzer_';
}
}
diff --git a/includes/gateways/Alipay.php b/includes/gateways/Alipay.php
old mode 100755
new mode 100644
index e4c8850..706a7f1
--- a/includes/gateways/Alipay.php
+++ b/includes/gateways/Alipay.php
@@ -2,6 +2,7 @@
namespace UnzerPayments\Gateways;
+use UnzerPayments\Gateways\Blocks\AlipayBlock;
use UnzerPayments\Services\PaymentService;
if ( ! defined( 'ABSPATH' ) ) {
@@ -10,7 +11,11 @@
class Alipay extends AbstractGateway {
- const GATEWAY_ID = 'unzer_alipay';
+ const GATEWAY_ID = 'unzer_alipay';
+ const BLOCK_CLASS = AlipayBlock::class;
+
+ public $allowedCountries = array( 'DE', 'AT', 'BE', 'IT', 'ES', 'NL' );
+ public $allowedCurrencies = array( 'AUD', 'CAD', 'CHF', 'CNY', 'EUR', 'GBP', 'HKD', 'NZD', 'SGD', 'USD' );
public $paymentTypeResource = \UnzerSDK\Resources\PaymentTypes\Alipay::class;
public $method_title = 'Unzer Alipay';
public $method_description;
diff --git a/includes/gateways/ApplePay.php b/includes/gateways/ApplePay.php
deleted file mode 100755
index d10ab3a..0000000
--- a/includes/gateways/ApplePay.php
+++ /dev/null
@@ -1,133 +0,0 @@
-get_description();
- if ( $description ) {
- echo wp_kses_post( wpautop( wptexturize( $description ) ) );
- }
- ?>
-
-
-
- is_enabled() ) {
- return;
- }
-
- $this->addCheckoutAssets();
- wp_enqueue_script( 'unzer_apple_pay_js', 'https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js', array(), UNZER_VERSION, array( 'in_footer' => false ) );
- }
-
- public function get_form_fields() {
- return apply_filters(
- 'wc_unzer_settings',
- array(
-
- 'enabled' => array(
- 'title' => __( 'Enable/Disable', 'unzer-payments' ),
- 'label' => __( 'Enable Unzer Apple Pay', 'unzer-payments' ),
- 'type' => 'checkbox',
- 'description' => '',
- 'default' => 'no',
- ),
- 'title' => array(
- 'title' => __( 'Title', 'unzer-payments' ),
- 'type' => 'text',
- 'description' => __( 'This controls the title which the user sees during checkout.', 'unzer-payments' ),
- 'default' => __( 'Apple Pay', 'unzer-payments' ),
- ),
- 'description' => array(
- 'title' => __( 'Description', 'unzer-payments' ),
- 'type' => 'text',
- 'description' => __( 'This controls the description which the user sees during checkout.', 'unzer-payments' ),
- 'default' => '',
- ),
- 'transaction_type' => array(
- 'title' => __( 'Charge or Authorize', 'unzer-payments' ),
- 'label' => '',
- 'type' => 'select',
- 'description' => __( 'Choose "authorize", if you you want to charge the shopper at a later point of time', 'unzer-payments' ),
- 'options' => array(
- AbstractGateway::TRANSACTION_TYPE_AUTHORIZE => __( 'authorize', 'unzer-payments' ),
- AbstractGateway::TRANSACTION_TYPE_CHARGE => __( 'charge', 'unzer-payments' ),
- ),
- 'default' => 'charge',
- ),
- 'merchant_id' => array(
- 'title' => __( 'Merchant ID', 'unzer-payments' ),
- 'type' => 'text',
- 'description' => '',
- 'default' => '',
- ),
- )
- );
- }
-
- public function process_payment( $order_id ) {
- $this->logger->debug( 'start payment for #' . $order_id . ' with ' . self::GATEWAY_ID );
- $return = array(
- 'result' => 'success',
- );
-
- $applePayId = Util::getNonceCheckedPostValue( 'unzer-apple-pay-id' );
-
- if ( empty( $applePayId ) ) {
- $this->logger->debug( 'apple pay empty id' );
- $return['messages'] = '';
- return $return;
- }
- if ( $this->get_option( 'transaction_type' ) === AbstractGateway::TRANSACTION_TYPE_AUTHORIZE ) {
- $transaction = ( new PaymentService() )->performAuthorizationForOrder( $order_id, $this, $applePayId );
- } else {
- $transaction = ( new PaymentService() )->performChargeForOrder( $order_id, $this, $applePayId );
- }
-
- $this->logger->debug( 'apple pay charge/authorization for order ' . $order_id, array( $transaction->expose() ) );
-
- if ( $transaction->getPayment()->getRedirectUrl() ) {
- $return['redirect'] = $transaction->getPayment()->getRedirectUrl();
- } else {
- $return['redirect'] = $this->get_confirm_url();
- }
- return $return;
- }
-
- public function get_additional_options_html() {
- include UNZER_PLUGIN_PATH . 'html/admin/apple-pay-settings.php';
- }
-}
diff --git a/includes/gateways/ApplePayV2.php b/includes/gateways/ApplePayV2.php
index 829415c..b90e875 100644
--- a/includes/gateways/ApplePayV2.php
+++ b/includes/gateways/ApplePayV2.php
@@ -1,7 +1,8 @@
get_description();
if ( $description ) {
echo wp_kses_post( wpautop( wptexturize( $description ) ) );
+ } else {
+ add_action(
+ 'wp_enqueue_scripts',
+ function () {
+ wp_add_inline_style( 'woocommerce_unzer_css', '.payment_box.payment_method_unzer_apple_pay_v2{display:none !important;}' );
+ }
+ );
}
- ?>
-
-
-
- is_enabled() ) {
- return;
- }
-
- $this->addCheckoutAssets();
+ Util::getNonceField();
+ $form = '
+
+
+
+
+
+
+
+
+ ';
+ echo wp_kses( $form, $this->get_allowed_html_tags() );
}
public function get_form_fields() {
@@ -98,12 +106,6 @@ public function process_payment( $order_id ) {
);
$applePayId = Util::getNonceCheckedPostValue( 'unzer-apple-pay-v2-id' );
-
- if ( empty( $applePayId ) ) {
- $this->logger->debug( 'apple pay empty id', $_POST );
- $return['messages'] = '';
- return $return;
- }
if ( $this->get_option( 'transaction_type' ) === AbstractGateway::TRANSACTION_TYPE_AUTHORIZE ) {
$transaction = ( new PaymentService() )->performAuthorizationForOrder( $order_id, $this, $applePayId );
} else {
@@ -112,10 +114,12 @@ public function process_payment( $order_id ) {
$this->logger->debug( 'apple pay charge/authorization for order ' . $order_id, array( $transaction->expose() ) );
+ $this->before_payment_redirect( $order_id );
+
if ( $transaction->getPayment()->getRedirectUrl() ) {
$return['redirect'] = $transaction->getPayment()->getRedirectUrl();
} else {
- $return['redirect'] = $this->get_confirm_url();
+ $return['redirect'] = $this->get_confirm_url( $order_id );
}
return $return;
}
diff --git a/includes/gateways/Bancontact.php b/includes/gateways/Bancontact.php
old mode 100755
new mode 100644
index 8dd61a9..bf0ce83
--- a/includes/gateways/Bancontact.php
+++ b/includes/gateways/Bancontact.php
@@ -2,6 +2,7 @@
namespace UnzerPayments\Gateways;
+use UnzerPayments\Gateways\Blocks\BancontactBlock;
use UnzerPayments\Services\PaymentService;
if ( ! defined( 'ABSPATH' ) ) {
@@ -11,6 +12,9 @@
class Bancontact extends AbstractGateway {
const GATEWAY_ID = 'unzer_bancontact';
+ const BLOCK_CLASS = BancontactBlock::class;
+ public $allowedCountries = array( 'BE' );
+ public $allowedCurrencies = array( 'EUR' );
public $paymentTypeResource = \UnzerSDK\Resources\PaymentTypes\Bancontact::class;
public $method_title = 'Unzer Bancontact';
public $method_description;
diff --git a/includes/gateways/Blocks/AbstractBlock.php b/includes/gateways/Blocks/AbstractBlock.php
new file mode 100644
index 0000000..dc8981a
--- /dev/null
+++ b/includes/gateways/Blocks/AbstractBlock.php
@@ -0,0 +1,150 @@
+ static::GATEWAY_ID,
+ 'title' => $gateway->title,
+ 'description' => $gateway->description,
+ 'allowedCountries' => $gateway->allowedCountries,
+ 'allowedCurrencies' => $gateway->allowedCurrencies,
+ 'publicKey' => $gateway->get_public_key(),
+ 'locale' => get_locale(),
+ 'nonce' => Util::getNonce(),
+ 'paymentComponentId' => str_replace( '_', '-', static::GATEWAY_ID ) . '-payment-component',
+ 'getCustomerDataUrl' => WC()->api_request_url( CheckoutController::GET_UNZER_CUSTOMER_SLUG ),
+ );
+ }
+
+ public function get_name() {
+ return $this->name;
+ }
+
+ public function is_active() {
+ $gatewayClass = static::GATEWAY_CLASS;
+ /** @var AbstractGateway $gateway */
+ $gateway = new $gatewayClass();
+ return $gateway->is_enabled();
+ }
+
+ public function get_script_data() {
+ return $this->get_payment_method_data();
+ }
+
+ protected function get_identifier() {
+ $identifier = 'unzer_simple';
+ if ( ! in_array( static::GATEWAY_ID, self::SIMPLE_PAYMENT_METHODS, true ) ) {
+ $identifier = static::GATEWAY_ID;
+ }
+ return $identifier;
+ }
+
+ public function get_payment_method_script_handles() {
+ return array( $this->get_identifier() . '-block-checkout' );
+ }
+
+
+ public function initialize() {
+ if ( ! $this->should_enqueue_assets() || is_admin() ) {
+ return;
+ }
+ // TODO replace when minimum WP version is 6.5 (wp_enqueue_script_module)
+ add_filter(
+ 'script_loader_tag',
+ function ( $tag, $handle, $src ) {
+ // if not your script, do nothing and return original $tag
+ if ( 'unzer_ui_v2_js' !== $handle ) {
+ return $tag;
+ }
+ // change the script tag by adding type="module" and return it.
+ $tag = '';
+ return $tag;
+ },
+ 10,
+ 3
+ );
+ wp_enqueue_script( 'unzer_ui_v2_js', 'https://static.test.unzer.com/v2/ui-components/index.js', array(), UNZER_VERSION, array( 'in_footer' => true ) ); // https://static-v2.unzer.com/v2/ui-components/index.js
+ wp_register_script( 'unzer_global-block-checkout', UNZER_PLUGIN_URL . '/assets/build/unzer_global.js', array( 'wc-blocks-registry' ), UNZER_VERSION, array( 'in_footer' => true ) );
+ wp_enqueue_script( 'unzer_global-block-checkout' );
+ $this->settings = array(
+ 'title' => $this->get_setting( 'title' ),
+ );
+ $identifier = $this->get_identifier();
+ $script_dependencies_path = UNZER_PLUGIN_PATH . 'assets/build/' . $identifier . '.asset.php';
+ $script_url = UNZER_PLUGIN_URL . '/assets/build/' . $identifier . '.js';
+ $style_path = UNZER_PLUGIN_PATH . 'assets/build/' . $identifier . '.css';
+ $style_url = UNZER_PLUGIN_URL . '/assets/build/' . $identifier . '.css';
+ $asset_handle = $identifier . '-block-checkout';
+
+ $script_dependencies = require $script_dependencies_path;
+ wp_register_script( $asset_handle, $script_url, $script_dependencies['dependencies'], $script_dependencies['version'], array( 'in_footer' => true ) );
+ if ( file_exists( $style_path ) ) {
+ wp_register_style( $asset_handle, $style_url, array(), UNZER_VERSION );
+ }
+
+ wp_set_script_translations( $asset_handle, 'unzer-payments' );
+
+ wp_enqueue_script( $asset_handle );
+ if ( wp_style_is( $asset_handle, 'registered' ) ) {
+ wp_enqueue_style( $asset_handle );
+ }
+ }
+
+ private function should_enqueue_assets(): bool {
+ $should_enqueue = ! is_order_received_page() && ! is_checkout_pay_page();
+
+ $is_cart_block_in_use = class_exists( CartCheckoutUtils::class ) && CartCheckoutUtils::is_cart_block_default();
+ $is_checkout_block_in_use = class_exists( CartCheckoutUtils::class ) && CartCheckoutUtils::is_checkout_block_default();
+
+ return $should_enqueue && ( wp_is_block_theme() || $is_cart_block_in_use || $is_checkout_block_in_use );
+ }
+}
diff --git a/includes/gateways/Blocks/AlipayBlock.php b/includes/gateways/Blocks/AlipayBlock.php
new file mode 100644
index 0000000..5568ebc
--- /dev/null
+++ b/includes/gateways/Blocks/AlipayBlock.php
@@ -0,0 +1,16 @@
+
-
- ';
- echo wp_kses_post( $this->renderSavedInstrumentsSelection( $form ) );
+ $form = '
+
+
+
+ get_option( 'allow_ctp' ) === 'yes' ? '' : 'disableCTP' ) . '
+ >
+
+
+ ';
+ echo wp_kses( $this->renderSavedInstrumentsSelection( $form ), $this->get_allowed_html_tags() );
}
public function get_form_fields() {
@@ -122,6 +110,17 @@ public function get_form_fields() {
'yes' => __( 'Yes', 'unzer-payments' ),
),
),
+ 'allow_ctp' => array(
+ 'title' => __( 'Offer Click To Pay', 'unzer-payments' ),
+ 'label' => __( ' ', 'unzer-payments' ),
+ 'type' => 'select',
+ 'description' => '',
+ 'default' => 'no',
+ 'options' => array(
+ 'no' => __( 'No', 'unzer-payments' ),
+ 'yes' => __( 'Yes', 'unzer-payments' ),
+ ),
+ ),
/*
'capture_trigger_order_status' => [
'title' => __('Capture status', 'unzer-payments'),
@@ -164,11 +163,11 @@ public function process_payment( $order_id ) {
} else {
$transaction = ( new PaymentService() )->performChargeForOrder( $order_id, $this, $cardId, $transactionEditorFunction );
}
-
+ $this->before_payment_redirect( $order_id );
if ( $transaction->getPayment()->getRedirectUrl() ) {
$return['redirect'] = $transaction->getPayment()->getRedirectUrl();
} elseif ( $transaction->isSuccess() ) {
- $return['redirect'] = $this->get_confirm_url();
+ $return['redirect'] = $this->get_confirm_url( $order_id );
}
return $return;
}
diff --git a/includes/gateways/DirectDebit.php b/includes/gateways/DirectDebit.php
old mode 100755
new mode 100644
index c134120..6b8007d
--- a/includes/gateways/DirectDebit.php
+++ b/includes/gateways/DirectDebit.php
@@ -3,6 +3,7 @@
namespace UnzerPayments\Gateways;
use Exception;
+use UnzerPayments\Gateways\Blocks\DirectDebitBlock;
use UnzerPayments\Services\PaymentService;
use UnzerPayments\Traits\SavePaymentInstrumentTrait;
use UnzerPayments\Util;
@@ -20,6 +21,8 @@ class DirectDebit extends AbstractGateway {
public $paymentTypeResource = SepaDirectDebit::class;
const GATEWAY_ID = 'unzer_direct_debit';
+ const BLOCK_CLASS = DirectDebitBlock::class;
+ public $allowedCurrencies = array( 'EUR' );
public $method_title = 'Unzer SEPA Direct Debit';
public $method_description;
public $title = 'SEPA Direct Debit';
@@ -57,45 +60,23 @@ public function payment_fields() {
echo wp_kses_post( wpautop( wptexturize( $description ) ) );
}
Util::getNonceField();
- $formId = uniqid();
- $form = '
-
-
-
-
+ $form = '
+
+
+
+
+
+
+
+
+
+
';
- echo wp_kses_post( $this->renderSavedInstrumentsSelection( $form ) );
- }
-
- public function payment_scripts() {
- if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) {
- return;
- }
-
- if ( ! $this->is_enabled() ) {
- return;
- }
-
- $this->addCheckoutAssets();
+ echo wp_kses( $this->renderSavedInstrumentsSelection( $form ), $this->get_allowed_html_tags() );
}
public function get_form_fields() {
@@ -103,32 +84,25 @@ public function get_form_fields() {
'wc_unzer_settings',
array(
- 'enabled' => array(
+ 'enabled' => array(
'title' => __( 'Enable/Disable', 'unzer-payments' ),
'label' => __( 'Enable Unzer SEPA Direct Debit Payments', 'unzer-payments' ),
'type' => 'checkbox',
'description' => '',
'default' => 'no',
),
- 'title' => array(
+ 'title' => array(
'title' => __( 'Title', 'unzer-payments' ),
'type' => 'text',
'description' => __( 'This controls the title which the user sees during checkout.', 'unzer-payments' ),
'default' => __( 'SEPA Direct Debit', 'unzer-payments' ),
),
- 'description' => array(
+ 'description' => array(
'title' => __( 'Description', 'unzer-payments' ),
'type' => 'text',
'description' => __( 'This controls the description which the user sees during checkout.', 'unzer-payments' ),
'default' => '',
),
- 'sepa_mandate' => array(
- 'title' => __( 'Alternative SEPA mandate description', 'unzer-payments' ),
- 'type' => 'textarea',
- 'description' => __( 'Leave empty to display the default text', 'unzer-payments' ),
- 'placeholder' => $this->defaultMandateText,
- 'default' => '',
- ),
AbstractGateway::SETTINGS_KEY_SAVE_INSTRUMENTS => array(
'title' => __( 'Save bank details for registered customers', 'unzer-payments' ),
'label' => __( ' ', 'unzer-payments' ),
@@ -168,8 +142,8 @@ public function process_payment( $order_id ) {
} else {
$this->set_order_transaction_number( wc_get_order( $order_id ), $charge->getPayment()->getId() );
}
- WC()->session->set( 'unzer_confirm_order_id', $order_id );
- $return['redirect'] = $this->get_confirm_url();
+ $this->before_payment_redirect( $order_id );
+ $return['redirect'] = $this->get_confirm_url( $order_id );
return $return;
}
diff --git a/includes/gateways/DirectDebitSecured.php b/includes/gateways/DirectDebitSecured.php
old mode 100755
new mode 100644
index b4b6783..2dbbd84
--- a/includes/gateways/DirectDebitSecured.php
+++ b/includes/gateways/DirectDebitSecured.php
@@ -3,12 +3,14 @@
namespace UnzerPayments\Gateways;
use Exception;
+use UnzerPayments\Gateways\Blocks\DirectDebitSecuredBlock;
use UnzerPayments\Services\OrderService;
use UnzerPayments\Services\PaymentService;
use UnzerPayments\Util;
use UnzerSDK\Exceptions\UnzerApiException;
use UnzerSDK\Resources\TransactionTypes\AbstractTransactionType;
use UnzerSDK\Resources\TransactionTypes\Authorization;
+use UnzerSDK\Resources\TransactionTypes\Charge;
use WC_Order;
if ( ! defined( 'ABSPATH' ) ) {
@@ -17,13 +19,17 @@
class DirectDebitSecured extends AbstractGateway {
- const GATEWAY_ID = 'unzer_direct_debit_secured';
- public $method_title = 'Unzer Direct Debit';
- public $method_description;
- public $title = 'Direct Debit';
- public $description = '';
- public $id = self::GATEWAY_ID;
+
+ const GATEWAY_ID = 'unzer_direct_debit_secured';
+ const BLOCK_CLASS = DirectDebitSecuredBlock::class;
+ public $allowedCountries = array( 'AT', 'DE' );
public $allowedCurrencies = array( 'EUR' );
+ public $isAllowedForB2B = false;
+ public $method_title = 'Unzer Direct Debit';
+ public $method_description;
+ public $title = 'Direct Debit';
+ public $description = '';
+ public $id = self::GATEWAY_ID;
public $plugin_id;
public $supports = array(
'products',
@@ -45,23 +51,25 @@ public function payment_fields() {
if ( $description ) {
echo wp_kses_post( wpautop( wptexturize( $description ) ) );
}
- Util::getNonceField();
- $formId = uniqid();
- ?>
-
-
-
-
-
-
-
- threatmetrix_payment_scripts();
+ Util::getNonceField();
+ $form = '
+
+
+
+
+
+
+
+
+
+ ';
+ echo wp_kses( $form, $this->get_allowed_html_tags() );
}
public function get_form_fields() {
@@ -113,24 +121,22 @@ public function get_form_fields() {
public function process_payment( $order_id ) {
$this->logger->debug( 'start payment for #' . $order_id . ' with ' . self::GATEWAY_ID );
- $order = wc_get_order( $order_id );
- $return = array(
+ $order = wc_get_order( $order_id );
+ $return = array(
'result' => 'success',
);
- $dob = Util::getNonceCheckedPostValue( 'unzer-direct-debit-secured-dob' );
- $this->handleDateOfBirth( $order, $dob );
- $_POST['unzer-dob'] = $dob; // for the unified handling in CustomerService and OrderService
- $paymentMeanId = Util::getNonceCheckedPostValue( 'unzer-direct-debit-secured-id' );
+ $paymentMeanId = Util::getNonceCheckedPostValue( 'unzer-direct-debit-secured-id' );
+ $riskId = Util::getNonceCheckedPostValue( 'unzer-direct-debit-secured-risk-id' );
$authorization = ( new PaymentService() )->performAuthorizationForOrder(
$order_id,
$this,
$paymentMeanId,
- function ( Authorization $authorization ) {
- AbstractGateway::addRiskDataToAuthorization( $authorization );
+ function ( Authorization $authorization ) use ( $riskId ) {
+ AbstractGateway::addRiskDataToAuthorization( $authorization, $riskId );
}
);
-
+ $this->before_payment_redirect( $order_id );
if ( $authorization->getPayment()->getRedirectUrl() ) {
$return['redirect'] = $authorization->getPayment()->getRedirectUrl();
} elseif ( $authorization->isSuccess() ) {
@@ -141,9 +147,8 @@ function ( Authorization $authorization ) {
// silent catch
}
WC()->session->set( 'unzer_confirm_order_id', $order_id );
- $return['redirect'] = $this->get_confirm_url();
+ $return['redirect'] = $this->get_confirm_url( $order_id );
}
- AbstractGateway::removeRiskDataFromSession();
return $return;
}
@@ -167,6 +172,10 @@ public function process_refund( $order_id, $amount = null, $reason = '' ) {
public function capture( WC_Order $order, $amount = null ) {
}
+ /**
+ * @param Charge|Authorization $chargeOrAuthorization
+ * @return string
+ */
public function get_payment_information( AbstractTransactionType $chargeOrAuthorization ) {
return sprintf(
__( "An amount of %1\$s will be deducted from your account using the descriptor '%2\$s' according to the SEPA mandate", 'unzer-payments' ),
@@ -174,4 +183,13 @@ public function get_payment_information( AbstractTransactionType $chargeOrAuthor
$chargeOrAuthorization->getDescriptor()
);
}
+
+ private function get_current_public_key() {
+ $keyName = 'public_key_eur_b2c';
+ $publicKey = $this->get_option( $keyName );
+ if ( empty( $publicKey ) ) {
+ $publicKey = get_option( 'unzer_public_key' );
+ }
+ return $publicKey;
+ }
}
diff --git a/includes/gateways/Eps.php b/includes/gateways/Eps.php
old mode 100755
new mode 100644
index aa208c1..58e2dca
--- a/includes/gateways/Eps.php
+++ b/includes/gateways/Eps.php
@@ -2,6 +2,7 @@
namespace UnzerPayments\Gateways;
+use UnzerPayments\Gateways\Blocks\EpsBlock;
use UnzerPayments\Services\PaymentService;
use UnzerPayments\Util;
@@ -12,6 +13,9 @@
class Eps extends AbstractGateway {
const GATEWAY_ID = 'unzer_eps';
+ const BLOCK_CLASS = EpsBlock::class;
+ public $allowedCountries = array( 'AT' );
+ public $allowedCurrencies = array( 'EUR' );
public $paymentTypeResource = \UnzerSDK\Resources\PaymentTypes\EPS::class;
public $method_title = 'Unzer EPS';
public $method_description;
diff --git a/includes/gateways/Giropay.php b/includes/gateways/Giropay.php
deleted file mode 100755
index 192bae7..0000000
--- a/includes/gateways/Giropay.php
+++ /dev/null
@@ -1,56 +0,0 @@
- array(
- 'title' => __( 'Enable/Disable', 'unzer-payments' ),
- 'label' => __( 'Enable Unzer Giropay', 'unzer-payments' ),
- 'type' => 'checkbox',
- 'description' => '',
- 'default' => 'no',
- ),
- 'title' => array(
- 'title' => __( 'Title', 'unzer-payments' ),
- 'type' => 'text',
- 'description' => __( 'This controls the title which the user sees during checkout.', 'unzer-payments' ),
- 'default' => __( 'Giropay', 'unzer-payments' ),
- ),
- 'description' => array(
- 'title' => __( 'Description', 'unzer-payments' ),
- 'type' => 'text',
- 'description' => __( 'This controls the description which the user sees during checkout.', 'unzer-payments' ),
- 'default' => '',
- ),
- )
- );
- }
-}
diff --git a/includes/gateways/GooglePay.php b/includes/gateways/GooglePay.php
index 03ec9fe..aad8762 100644
--- a/includes/gateways/GooglePay.php
+++ b/includes/gateways/GooglePay.php
@@ -1,7 +1,8 @@
-
-
- is_enabled() ) {
- return;
- }
- $this->addCheckoutAssets();
- wp_enqueue_script( 'unzer_google_pay_js', 'https://pay.google.com/gp/p/js/pay.js', array(), UNZER_VERSION, array( 'in_footer' => false ) );
+ Util::getNonceField();
+ $form = '
+
+
+
+
+
+
+
+
+ ';
+ echo wp_kses( $form, $this->get_allowed_html_tags() );
}
public function get_form_fields() {
@@ -211,12 +212,6 @@ public function process_payment( $order_id ) {
);
$googlePayId = Util::getNonceCheckedPostValue( 'unzer-google-pay-id' );
-
- if ( empty( $googlePayId ) ) {
- $this->logger->debug( 'google pay empty id' );
- $return['messages'] = '';
- return $return;
- }
if ( $this->get_option( 'transaction_type' ) === AbstractGateway::TRANSACTION_TYPE_AUTHORIZE ) {
$transaction = ( new PaymentService() )->performAuthorizationForOrder( $order_id, $this, $googlePayId );
} else {
@@ -224,11 +219,11 @@ public function process_payment( $order_id ) {
}
$this->logger->debug( 'google pay charge/authorization for order ' . $order_id, array( $transaction->expose() ) );
-
+ $this->before_payment_redirect( $order_id );
if ( $transaction->getPayment()->getRedirectUrl() ) {
$return['redirect'] = $transaction->getPayment()->getRedirectUrl();
} else {
- $return['redirect'] = $this->get_confirm_url();
+ $return['redirect'] = $this->get_confirm_url( $order_id );
}
return $return;
}
diff --git a/includes/gateways/Ideal.php b/includes/gateways/Ideal.php
old mode 100755
new mode 100644
index cb45a86..0e7b15f
--- a/includes/gateways/Ideal.php
+++ b/includes/gateways/Ideal.php
@@ -2,8 +2,7 @@
namespace UnzerPayments\Gateways;
-use UnzerPayments\Services\PaymentService;
-use UnzerPayments\Util;
+use UnzerPayments\Gateways\Blocks\IdealBlock;
if ( ! defined( 'ABSPATH' ) ) {
exit;
@@ -11,8 +10,13 @@
class Ideal extends AbstractGateway {
- const GATEWAY_ID = 'unzer_ideal';
- public $method_title = 'Unzer iDEAL';
+
+ const GATEWAY_ID = 'unzer_ideal';
+ const BLOCK_CLASS = IdealBlock::class;
+ public $paymentTypeResource = \UnzerSDK\Resources\PaymentTypes\Ideal::class;
+ public $allowedCountries = array( 'NL' );
+ public $allowedCurrencies = array( 'EUR' );
+ public $method_title = 'Unzer iDEAL';
public $method_description;
public $title = 'iDEAL';
public $description = '';
@@ -23,24 +27,6 @@ class Ideal extends AbstractGateway {
'refunds',
);
- public function has_fields() {
- return true;
- }
-
- public function payment_fields() {
- $description = $this->get_description();
- if ( $description ) {
- echo wp_kses_post( wpautop( wptexturize( $description ) ) );
- }
- Util::getNonceField();
- ?>
-
- logger->debug( 'start payment for #' . $order_id . ' with ' . self::GATEWAY_ID );
- $return = array(
- 'result' => 'success',
- );
- $transaction = ( new PaymentService() )->performChargeForOrder( $order_id, $this, Util::getNonceCheckedPostValue( 'unzer-ideal-id' ) );
- if ( $transaction->getPayment()->getRedirectUrl() ) {
- $return['redirect'] = $transaction->getPayment()->getRedirectUrl();
- }
- return $return;
- }
}
diff --git a/includes/gateways/Installment.php b/includes/gateways/Installment.php
old mode 100755
new mode 100644
index 62e7b18..b33d8af
--- a/includes/gateways/Installment.php
+++ b/includes/gateways/Installment.php
@@ -3,12 +3,14 @@
namespace UnzerPayments\Gateways;
use Exception;
+use UnzerPayments\Gateways\Blocks\InstallmentBlock;
use UnzerPayments\Services\OrderService;
use UnzerPayments\Services\PaymentService;
use UnzerPayments\Util;
use UnzerSDK\Exceptions\UnzerApiException;
use UnzerSDK\Resources\TransactionTypes\AbstractTransactionType;
use UnzerSDK\Resources\TransactionTypes\Authorization;
+use UnzerSDK\Resources\TransactionTypes\Charge;
if ( ! defined( 'ABSPATH' ) ) {
exit;
@@ -17,19 +19,21 @@
class Installment extends AbstractGateway {
- const GATEWAY_ID = 'unzer_installment';
- public $method_title = 'Unzer Installment';
+ const GATEWAY_ID = 'unzer_installment';
+ const BLOCK_CLASS = InstallmentBlock::class;
+ public $allowedCurrencies = array( 'EUR', 'CHF' );
+ public $allowedCountries = array( 'AT', 'CH', 'DE' );
+ public $isAllowedForB2B = false;
+ public $method_title = 'Unzer Installment';
public $method_description;
public $title = 'Installment';
public $description = '';
public $id = self::GATEWAY_ID;
public $plugin_id;
- public $supports = array(
+ public $supports = array(
'products',
'refunds',
);
- public $allowedCurrencies = array( 'EUR', 'CHF' );
- public $allowedCountries = array( 'AT', 'CH', 'DE' );
public function __construct() {
parent::__construct();
@@ -46,24 +50,34 @@ public function payment_fields() {
echo wp_kses_post( wpautop( wptexturize( $description ) ) );
}
Util::getNonceField();
- ?>
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+ ';
+ echo wp_kses( $form, $this->get_allowed_html_tags() );
}
- public function payment_scripts() {
- $this->threatmetrix_payment_scripts();
+ public function get_current_public_key() {
+ $currency = get_woocommerce_currency();
+ $keyName = 'public_key_' . strtolower( $currency ) . '_b2c';
+ $publicKey = $this->get_option( $keyName );
+ if ( empty( $publicKey ) ) {
+ $publicKey = get_option( 'unzer_public_key' );
+ }
+ return $publicKey;
}
public function get_form_fields() {
@@ -154,19 +168,15 @@ public function process_payment( $order_id ) {
'result' => 'success',
);
$order = wc_get_order( $order_id );
-
- $dob = Util::getNonceCheckedPostValue( 'unzer-installment-dob' );
- $this->handleDateOfBirth( $order, $dob );
- $_POST['unzer-dob'] = $dob;
$order->save_meta_data();
-
+ $riskId = Util::getNonceCheckedPostValue( 'unzer-installment-risk-id' );
try {
$authorization = ( new PaymentService() )->performAuthorizationForOrder(
$order_id,
$this,
Util::getNonceCheckedPostValue( 'unzer-installment-id' ),
- function ( Authorization $authorization ) {
- AbstractGateway::addRiskDataToAuthorization( $authorization );
+ function ( Authorization $authorization ) use ( $riskId ) {
+ AbstractGateway::addRiskDataToAuthorization( $authorization, $riskId );
}
);
} catch ( UnzerApiException $e ) {
@@ -175,6 +185,7 @@ function ( Authorization $authorization ) {
if ( ! ( $authorization->isPending() || $authorization->isSuccess() ) ) {
throw new Exception( esc_html( $authorization->getMessage()->getCustomer() ) );
}
+
if ( $authorization->isSuccess() ) {
$order = wc_get_order( $order_id );
$orderService = new OrderService();
@@ -182,11 +193,14 @@ function ( Authorization $authorization ) {
} else {
$this->set_order_transaction_number( wc_get_order( $order_id ), $authorization->getPayment()->getId() );
}
+ $this->before_payment_redirect( $order_id );
$return['redirect'] = $this->get_return_url( wc_get_order( $order_id ) );
- AbstractGateway::removeRiskDataFromSession();
return $return;
}
-
+ /**
+ * @param Charge|Authorization $chargeOrAuthorization
+ * @return string
+ */
public function get_payment_information( AbstractTransactionType $chargeOrAuthorization ) {
return sprintf(
__(
diff --git a/includes/gateways/Invoice.php b/includes/gateways/Invoice.php
old mode 100755
new mode 100644
index 18f2af8..5c19294
--- a/includes/gateways/Invoice.php
+++ b/includes/gateways/Invoice.php
@@ -3,6 +3,7 @@
namespace UnzerPayments\Gateways;
use Exception;
+use UnzerPayments\Gateways\Blocks\InvoiceBlock;
use UnzerPayments\Main;
use UnzerPayments\Services\OrderService;
use UnzerPayments\Services\PaymentService;
@@ -10,6 +11,7 @@
use UnzerSDK\Exceptions\UnzerApiException;
use UnzerSDK\Resources\TransactionTypes\AbstractTransactionType;
use UnzerSDK\Resources\TransactionTypes\Authorization;
+use UnzerSDK\Resources\TransactionTypes\Charge;
if ( ! defined( 'ABSPATH' ) ) {
exit;
@@ -18,8 +20,11 @@
class Invoice extends AbstractGateway {
- const GATEWAY_ID = 'unzer_invoice';
- public $method_title = 'Unzer Invoice';
+ const GATEWAY_ID = 'unzer_invoice';
+ const BLOCK_CLASS = InvoiceBlock::class;
+ public $allowedCurrencies = array( 'EUR', 'CHF' );
+ public $allowedCountries = array( 'AT', 'CH', 'DE', 'NL' );
+ public $method_title = 'Unzer Invoice';
public $method_description;
public $title = 'Invoice';
public $description = '';
@@ -30,8 +35,6 @@ class Invoice extends AbstractGateway {
'refunds',
);
- public $allowedCurrencies = array( 'EUR', 'CHF' );
- public $allowedCountries = array( 'AT', 'CH', 'DE', 'NL' );
public function __construct() {
parent::__construct();
@@ -152,37 +155,37 @@ public function payment_fields() {
echo wp_kses_post( wpautop( wptexturize( $description ) ) );
}
Util::getNonceField();
- ?>
-
-
-
-
-
-
-
-
-
- threatmetrix_payment_scripts();
+ $form = '
+
+
+
+
+
+
+
+
+
+
+ ';
+ echo wp_kses( $form, $this->get_allowed_html_tags() );
}
+ public function get_current_public_key() {
+ $currency = get_woocommerce_currency();
+ $isB2C = empty( $this->get_company_from_post() );
+ $keyName = 'public_key_' . strtolower( $currency ) . '_' . ( $isB2C ? 'b2c' : 'b2b' );
+ $publicKey = $this->get_option( $keyName );
+ if ( empty( $publicKey ) ) {
+ $publicKey = get_option( 'unzer_public_key' );
+ }
+ return $publicKey;
+ }
/**
* @param $order_id
@@ -193,33 +196,14 @@ public function process_payment( $order_id ) {
$return = array(
'result' => 'success',
);
- $order = wc_get_order( $order_id );
-
- if ( !$order->get_billing_company() ) {
- $dob = Util::getNonceCheckedPostValue('unzer-invoice-dob');
- $this->handleDateOfBirth($order, $dob);
- $_POST['unzer-dob'] = $dob; // for unified handling in CustomerService and OrderService
- } elseif ( $order->get_billing_company() ) {
- $companyType = (string) Util::getNonceCheckedPostValue( 'unzer-invoice-company-type' );
- if ( empty( $companyType ) ) {
- throw new Exception( esc_html__( 'Please enter your company type', 'unzer-payments' ) );
- }
- if ($companyType === 'sole') {
- $dob = Util::getNonceCheckedPostValue('unzer-invoice-dob');
- $this->handleDateOfBirth($order, $dob);
- $_POST['unzer-dob'] = $dob; // for unified handling in CustomerService and OrderService
- }
- $order->update_meta_data( Main::ORDER_META_KEY_COMPANY_TYPE, $companyType );
- }
- $order->save_meta_data();
-
+ $riskId = Util::getNonceCheckedPostValue( 'unzer-invoice-risk-id' );
try {
$authorization = ( new PaymentService() )->performAuthorizationForOrder(
$order_id,
$this,
Util::getNonceCheckedPostValue( 'unzer-invoice-id' ),
- function ( Authorization $authorization ) {
- AbstractGateway::addRiskDataToAuthorization( $authorization );
+ function ( Authorization $authorization ) use ( $riskId ) {
+ AbstractGateway::addRiskDataToAuthorization( $authorization, $riskId );
}
);
} catch ( UnzerApiException $e ) {
@@ -235,8 +219,8 @@ function ( Authorization $authorization ) {
} else {
$this->set_order_transaction_number( wc_get_order( $order_id ), $authorization->getPayment()->getId() );
}
+ $this->before_payment_redirect( $order_id );
$return['redirect'] = $this->get_return_url( wc_get_order( $order_id ) );
- AbstractGateway::removeRiskDataFromSession();
return $return;
}
@@ -253,6 +237,10 @@ public function process_refund( $order_id, $amount = null, $reason = '' ) {
}
+ /**
+ * @param Charge|Authorization $chargeOrAuthorization
+ * @return string
+ */
public function get_payment_information( AbstractTransactionType $chargeOrAuthorization ) {
return sprintf(
__(
diff --git a/includes/gateways/Klarna.php b/includes/gateways/Klarna.php
old mode 100755
new mode 100644
index f4fb701..f06b7e4
--- a/includes/gateways/Klarna.php
+++ b/includes/gateways/Klarna.php
@@ -2,8 +2,10 @@
namespace UnzerPayments\Gateways;
+use UnzerPayments\Gateways\Blocks\KlarnaBlock;
use UnzerPayments\Services\PaymentService;
-use UnzerSDK\Resources\TransactionTypes\Charge;
+use UnzerSDK\Exceptions\UnzerApiException;
+use UnzerSDK\Resources\TransactionTypes\Authorization;
if ( ! defined( 'ABSPATH' ) ) {
exit;
@@ -11,8 +13,117 @@
class Klarna extends AbstractGateway {
- const GATEWAY_ID = 'unzer_klarna';
- public $method_title = 'Unzer Klarna';
+
+
+ const GATEWAY_ID = 'unzer_klarna';
+ const BLOCK_CLASS = KlarnaBlock::class;
+ public $allowedCountryCurrencySets = array(
+ array(
+ 'country' => 'AU',
+ 'currency' => 'AUD',
+ ),
+ array(
+ 'country' => 'AT',
+ 'currency' => 'EUR',
+ ),
+ array(
+ 'country' => 'BE',
+ 'currency' => 'EUR',
+ ),
+ array(
+ 'country' => 'CA',
+ 'currency' => 'CAD',
+ ),
+ array(
+ 'country' => 'CZ',
+ 'currency' => 'CZK',
+ ),
+ array(
+ 'country' => 'DK',
+ 'currency' => 'DKK',
+ ),
+ array(
+ 'country' => 'FI',
+ 'currency' => 'EUR',
+ ),
+ array(
+ 'country' => 'FR',
+ 'currency' => 'EUR',
+ ),
+ array(
+ 'country' => 'DE',
+ 'currency' => 'EUR',
+ ),
+ array(
+ 'country' => 'GR',
+ 'currency' => 'EUR',
+ ),
+ array(
+ 'country' => 'HU',
+ 'currency' => 'HUF',
+ ),
+ array(
+ 'country' => 'IE',
+ 'currency' => 'EUR',
+ ),
+ array(
+ 'country' => 'IT',
+ 'currency' => 'EUR',
+ ),
+ array(
+ 'country' => 'MX',
+ 'currency' => 'MXN',
+ ),
+ array(
+ 'country' => 'NL',
+ 'currency' => 'EUR',
+ ),
+ array(
+ 'country' => 'NZ',
+ 'currency' => 'NZD',
+ ),
+ array(
+ 'country' => 'NO',
+ 'currency' => 'NOK',
+ ),
+ array(
+ 'country' => 'PL',
+ 'currency' => 'PLN',
+ ),
+ array(
+ 'country' => 'PT',
+ 'currency' => 'EUR',
+ ),
+ array(
+ 'country' => 'RO',
+ 'currency' => 'RON',
+ ),
+ array(
+ 'country' => 'SK',
+ 'currency' => 'EUR',
+ ),
+ array(
+ 'country' => 'ES',
+ 'currency' => 'EUR',
+ ),
+ array(
+ 'country' => 'SE',
+ 'currency' => 'SEK',
+ ),
+ array(
+ 'country' => 'CH',
+ 'currency' => 'CHF',
+ ),
+ array(
+ 'country' => 'GB',
+ 'currency' => 'GBP',
+ ),
+ array(
+ 'country' => 'US',
+ 'currency' => 'USD',
+ ),
+ );
+ public $method_title = 'Unzer Klarna';
public $method_description;
public $title = 'Klarna';
public $description = '';
@@ -55,20 +166,33 @@ public function process_payment( $order_id ) {
$return = array(
'result' => 'success',
);
- $charge = ( new PaymentService() )->performChargeForOrder(
+ $charge = ( new PaymentService() )->performAuthorizationForOrder(
$order_id,
$this,
\UnzerSDK\Resources\PaymentTypes\Klarna::class,
- function ( Charge $charge ) {
- $charge
- ->setTermsAndConditionUrl( 'https://google.com' )
- ->setPrivacyPolicyUrl( 'https://google.com/de/' );
+ function ( Authorization $authorization ) {
+ $authorization
+ ->setTermsAndConditionUrl( 'https://unzer.com' )
+ ->setPrivacyPolicyUrl( 'https://unzer.com' );
}
);
+ $this->before_payment_redirect( $order_id );
+
if ( $charge->getPayment()->getRedirectUrl() ) {
$return['redirect'] = $charge->getPayment()->getRedirectUrl();
}
return $return;
}
+
+ /**
+ * @param $order_id
+ * @param $amount
+ * @param $reason
+ * @return bool
+ * @throws UnzerApiException
+ */
+ public function process_refund( $order_id, $amount = null, $reason = '' ) {
+ return $this->process_refund_on_payment( $order_id, $amount, $reason );
+ }
}
diff --git a/includes/gateways/OpenBanking.php b/includes/gateways/OpenBanking.php
index 2fd5096..e06835e 100644
--- a/includes/gateways/OpenBanking.php
+++ b/includes/gateways/OpenBanking.php
@@ -1,9 +1,8 @@
-
-
-
-
-
-
+