Skip to content

Instantly share code, notes, and snippets.

@vanbo
Last active July 30, 2020 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanbo/158f91a500a3f8d3e75ed63cda6da219 to your computer and use it in GitHub Desktop.
Save vanbo/158f91a500a3f8d3e75ed63cda6da219 to your computer and use it in GitHub Desktop.
WooCommerce Psigate multi-currency setup
/**
* The code goes into your "theme\functions.php" file or any php file that is loaded on page load.
*/
// AM API Process Payment
add_filter( 'wc_psigate_process_acc_manager_payment_parameters', 'psigate_modify_account_manager_api_credentials_on_currency', 10, 2 );
// AM API Register Customer Account
add_filter( 'wc_psigate_register_customer_account_parameters', 'psigate_modify_account_manager_api_credentials_on_currency', 10, 2 );
/**
* Modifies the Account Manager API credentials, based on currency code
*
* @param array $parameters
* @param WC_Order $order
*
* @return array
*/
function psigate_modify_account_manager_api_credentials_on_currency( $parameters, $order ) {
/**
* IMPORTANT: For the default currency the setting "Store ID" in the plugin settings is used.
* You can still overwrite it here by adding the default currency
*/
/**
* NOTE: Remove the currency you don't need or add StoreID for both.
*/
if ( 'USD' == \WcPsigate\Compatibility::get_order_currency( $order ) ) {
if ( isset( $parameters['Charge'] ) && isset( $parameters['Charge']['StoreID'] ) ) {
$parameters['Charge']['StoreID'] = 'USD StoreID for the currency';
}
}
if ( 'CAD' == \WcPsigate\Compatibility::get_order_currency( $order ) ) {
if ( isset( $parameters['Charge'] ) && isset( $parameters['Charge']['StoreID'] ) ) {
$parameters['Charge']['StoreID'] = 'CAD StoreID for the currency';
}
}
return $parameters;
}
// XML API Process Payment
add_filter( 'wc_psigate_process_credit_card_payment_parameters', 'psigate_modify_xml_api_credentials_on_currency', 10, 2 );
// XML API Process Refund
add_filter( 'wc_psigate_process_refund_parameters', 'psigate_modify_xml_api_credentials_on_currency', 10, 2 );
/**
* Modifies the XML API credentials, based on currency code
*
* @param array $parameters
* @param WC_Order $order
*
* @return array
*/
function psigate_modify_xml_api_credentials_on_currency( $parameters, $order ) {
// Enter here the currency code you want to have additional account for.
// Currency it is set to CAD or USD or any currency you want
if ( 'CAD' == \WcPsigate\Compatibility::get_order_currency( $order ) ) {
/**
* Important: Credentials for the XML API, based on the currency
*/
if ( isset( $parameters['StoreID'] ) ) {
$parameters['StoreID'] = 'StoreID for the currency';
}
if ( isset( $parameters['Passphrase'] ) ) {
$parameters['Passphrase'] = 'Passphrase for the currency';
}
}
return $parameters;
}
// AM Create account from Payment
add_filter( 'wc_psigate_create_am_account_from_payment_parameters', 'psigate_create_account_from_payment_on_currency', 10, 3 );
/**
* Modifies the AM API parameters for Create account from payment request
*
* @param array $parameters
* @param WC_Order $order
*
* @return array
*/
function psigate_create_account_from_payment_on_currency( $parameters, $order, $payment_response ) {
// Enter here the currency code you want to have additional account for.
// Currency it is set to CAD or USD or any currency you want
if ( 'USD' == \WcPsigate\Compatibility::get_order_currency( $order ) ) {
if ( isset( $parameters['Condition'] ) && isset( $parameters['Condition']['StoreID'] ) ) {
$parameters['Condition']['StoreID'] = 'USD StoreID for the currency';
}
}
if ( 'CAD' == \WcPsigate\Compatibility::get_order_currency( $order ) ) {
if ( isset( $parameters['Condition'] ) && isset( $parameters['Condition']['StoreID'] ) ) {
$parameters['Condition']['StoreID'] = 'CAD StoreID for the currency';
}
}
return $parameters;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment