Last active
January 17, 2020 10:20
-
-
Save vanbo/b97e8a9b6c4df6ed19cf4c902007fb40 to your computer and use it in GitHub Desktop.
WooCommerce Paysafe Checkout API Dynamic Account ID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'wc_paysafe_checkoutjs_account_id', 'prefix_paysafe_checkout_api_account_id', 10, 3 ); | |
/** | |
* @param string $account_id The default Account ID for the type | |
* @param \WcPaysafe\Api\Data_Sources\Order_Source|\WcPaysafe\Api\Data_Sources\User_Source $data_source | |
* @param string $payment_type The type of payment to be processed. | |
* Possible values: cards|directdebit|interac|iframe | |
* Note : The $payment_type values explained: | |
* 1. cards - Cards API transaction | |
* 2. directdebit - Direct Debit API transaction | |
* 3. interac - Interac transaction - not yet supported | |
* 4. iframe - Setup for the Paysafe Checkout JS iframe. | |
* Default the "cards" account ID is used | |
* | |
* @return string | |
*/ | |
function prefix_paysafe_checkout_api_account_id( $account_id, $data_source, $payment_type ) { | |
// If we don't have a data source, the we are going to use the default account_id | |
if ( null == $data_source ) { | |
return $account_id; | |
} | |
// What type of payment we will use | |
if ( 'cards' == $payment_type ) { | |
// Currency check | |
if ( 'USD' == $data_source->get_currency() ) { | |
$account_id = 'USD-cards-account-id-value'; | |
} | |
} elseif ( 'directdebit' == $payment_type ) { | |
// Currency check | |
if ( 'USD' == $data_source->get_currency() ) { | |
$account_id = 'USD-dd-account-id-value'; | |
} | |
} elseif ( 'iframe' == $payment_type ) { | |
// Currency check | |
if ( 'USD' == $data_source->get_currency() ) { | |
// The account ID in the layover is used to process 3DS authentication for card payments | |
// Usually the account ID here will be the same as the 'cards' account ID | |
$account_id = 'USD-cards-account-id-value'; | |
} | |
} | |
/** | |
* If you need to change the account_id based on the customer billing info | |
* The example shows check against the billing country | |
*/ | |
if ( 'US' == $data_source->get_billing_country() ) { | |
$account_id = 'account-id-for-US'; | |
} | |
return $account_id; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment