Last active
May 26, 2020 12:57
-
-
Save Alexisgt01/e0a943d7302befc7fb1a03b83edd88a9 to your computer and use it in GitHub Desktop.
Modification ma valise en carton
This file contains hidden or 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
// wp-content/plugins/payline-woocommerce-master/class-wc-gateway-payline.php | |
function payline_callback() | |
{ | |
if (isset($_GET['order_id'])) { | |
$this->generate_payline_form($_GET['order_id']); | |
exit; | |
} | |
$this->SDK = new PaylineSDK($this->settings['merchant_id'], $this->settings['access_key'], $this->settings['proxy_host'], $this->settings['proxy_port'], $this->settings['proxy_login'], $this->settings['proxy_password'], $this->settings['environment']); | |
$this->SDK->usedBy('wooComm ' . $this->extensionVersion); | |
$res = $this->SDK->getWebPaymentDetails([ | |
'token' => $_GET['token'], | |
'version' => '2' | |
]); | |
if ($res['result']['code'] == PaylineSDK::ERR_CODE) { | |
$this->SDK->getLogger()->addError('Unable to call Payline for token ' . $_GET['token']); | |
exit; | |
} else { | |
$orderId = $res['order']['ref']; | |
$order = new WC_Order($orderId); | |
$expectedToken = get_option('plnTokenForOrder_' . $orderId); | |
if ($expectedToken != $_GET['token']) { | |
$message = 'Token ' . $_GET['token'] . ' does not match expected ' . $expectedToken . ' for order ' . $orderId; | |
$this->SDK->getLogger()->addError($message); | |
$order->add_order_note($message); | |
die($message); | |
} | |
if ($res['result']['code'] == '00000') { | |
// Store transaction details | |
update_post_meta((int)$orderId, 'Transaction ID', $res['transaction']['id']); | |
update_post_meta((int)$orderId, 'Card number', $res['card']['number']); | |
update_post_meta((int)$orderId, 'Payment mean', $res['card']['type']); | |
update_post_meta((int)$orderId, 'Card expiry', $res['card']['expirationDate']); | |
$order->payment_complete(); | |
wp_redirect($this->get_return_url($order)); | |
die(); | |
} elseif ($res['result']['code'] == '04003') { | |
update_post_meta((int)$orderId, 'Transaction ID', $res['transaction']['id']); | |
update_post_meta((int)$orderId, 'Card number', $res['card']['number']); | |
update_post_meta((int)$orderId, 'Payment mean', $res['card']['type']); | |
update_post_meta((int)$orderId, 'Card expiry', $res['card']['expirationDate']); | |
$order->update_status('on-hold', 'Fraud alert. See details in Payline administration center. '); | |
wp_redirect($this->get_return_url($order)); | |
die(); | |
} elseif ($res['result']['code'] == '02319') { | |
$order->update_status('cancelled', 'Buyer cancelled his payment'); | |
wp_redirect($order->get_cancel_order_url()); | |
die(); | |
} elseif ($res['result']['code'] == '02304' || $res['result']['code'] == '02324') { | |
$order->update_status('cancelled', 'Payment session expired without transaction'); | |
wp_redirect($order->get_cancel_order_url()); | |
die(); | |
} elseif ($res['result']['code'] == '02534' || $res['result']['code'] == '02324') { | |
$order->update_status('cancelled', 'Payment session expired with no redirection on payment page'); | |
wp_redirect($order->get_cancel_order_url()); | |
die(); | |
} elseif ($res['result']['code'] == '02306' || $res['result']['code'] == '02533') { | |
$order->add_order_note('Payment in progress'); | |
die('Payment in progress'); | |
} else { | |
if ($res['transaction']['id']) { | |
update_post_meta((int)$orderId, 'Transaction ID', $res['transaction']['id']); | |
} | |
$order->update_status('failed', 'Payment refused (code ' . $res['result']['code'] . ' : ' . $res['result']['longMessage']); | |
wp_redirect($this->get_return_url($order)); | |
die(); | |
} | |
} | |
} |
This file contains hidden or 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
// wp-content/plugins/payline-woocommerce-master/class-wc-gateway-payline.php | |
private $custom_token = 'paylinetoken'; | |
function payline_callback() | |
{ | |
if (isset($_GET['order_id'])) { | |
$this->generate_payline_form($_GET['order_id']); | |
exit; | |
} | |
$this->SDK = new PaylineSDK($this->settings['merchant_id'], $this->settings['access_key'], $this->settings['proxy_host'], $this->settings['proxy_port'], $this->settings['proxy_login'], $this->settings['proxy_password'], $this->settings['environment']); | |
$this->SDK->usedBy('wooComm ' . $this->extensionVersion); | |
$res = $this->SDK->getWebPaymentDetails([ | |
'token' => $_GET[$this->custom_token], | |
'version' => '2' | |
]); | |
if ($res['result']['code'] == PaylineSDK::ERR_CODE) { | |
$this->SDK->getLogger()->addError('Unable to call Payline for token ' . $_GET[$this->custom_token]); | |
exit; | |
} else { | |
$orderId = $res['order']['ref']; | |
$order = new WC_Order($orderId); | |
$expectedToken = get_option('plnTokenForOrder_' . $orderId); | |
if ($expectedToken != $_GET[$this->custom_token]) { | |
$message = 'Token ' . $_GET[$this->custom_token] . ' does not match expected ' . $expectedToken . ' for order ' . $orderId; | |
$this->SDK->getLogger()->addError($message); | |
$order->add_order_note($message); | |
die($message); | |
} | |
if ($res['result']['code'] == '00000') { | |
// Store transaction details | |
update_post_meta((int)$orderId, 'Transaction ID', $res['transaction']['id']); | |
update_post_meta((int)$orderId, 'Card number', $res['card']['number']); | |
update_post_meta((int)$orderId, 'Payment mean', $res['card']['type']); | |
update_post_meta((int)$orderId, 'Card expiry', $res['card']['expirationDate']); | |
$order->payment_complete(); | |
wp_redirect($this->get_return_url($order)); | |
die(); | |
} elseif ($res['result']['code'] == '04003') { | |
update_post_meta((int)$orderId, 'Transaction ID', $res['transaction']['id']); | |
update_post_meta((int)$orderId, 'Card number', $res['card']['number']); | |
update_post_meta((int)$orderId, 'Payment mean', $res['card']['type']); | |
update_post_meta((int)$orderId, 'Card expiry', $res['card']['expirationDate']); | |
$order->update_status('on-hold', 'Fraud alert. See details in Payline administration center. '); | |
wp_redirect($this->get_return_url($order)); | |
die(); | |
} elseif ($res['result']['code'] == '02319') { | |
$order->update_status('cancelled', 'Buyer cancelled his payment'); | |
wp_redirect($order->get_cancel_order_url()); | |
die(); | |
} elseif ($res['result']['code'] == '02304' || $res['result']['code'] == '02324') { | |
$order->update_status('cancelled', 'Payment session expired without transaction'); | |
wp_redirect($order->get_cancel_order_url()); | |
die(); | |
} elseif ($res['result']['code'] == '02534' || $res['result']['code'] == '02324') { | |
$order->update_status('cancelled', 'Payment session expired with no redirection on payment page'); | |
wp_redirect($order->get_cancel_order_url()); | |
die(); | |
} elseif ($res['result']['code'] == '02306' || $res['result']['code'] == '02533') { | |
$order->add_order_note('Payment in progress'); | |
die('Payment in progress'); | |
} else { | |
if ($res['transaction']['id']) { | |
update_post_meta((int)$orderId, 'Transaction ID', $res['transaction']['id']); | |
} | |
$order->update_status('failed', 'Payment refused (code ' . $res['result']['code'] . ' : ' . $res['result']['longMessage']); | |
wp_redirect($this->get_return_url($order)); | |
die(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment