payline
- require_once 'payline.inc';
- require_once 'vendor/autoload.php';
- use \Payline\PaylineSDK;
Loads the configuration file.
Initializes the access to the code of the class PaylineSDK
.
- function payline_sdk() {
- global $payline_merchant_id, $payline_access_key;
- global $payline_proxy_host, $payline_proxy_port, $payline_proxy_login, $payline_proxy_password;
- global $payline_context;
- static $sdk=null;
- if (!$sdk) {
- $sdk = new PaylineSDK($payline_merchant_id, $payline_access_key, $payline_proxy_host, $payline_proxy_port, $payline_proxy_login, $payline_proxy_password, $payline_context == 'prod' ? PaylineSDK::ENV_PROD : PaylineSDK::ENV_HOMO);
- }
- return $sdk;
- }
payline_sdk
creates and returns a uniq instance of the SDK initialized with the parameters defined in the configuration file payline.inc in mode approval or production according to the value of the parameter $payline_context
.
- function payline_dowebpayment($params) {
- global $payline_log;
- $sdk = payline_sdk();
- if (!$sdk) {
- return false;
- }
- $r = $sdk->doWebPayment($params);
- if ($payline_log) {
- logpayline('WebPayment', $r);
- }
- return $r;
- }
payline_dowebpayment
sends a WebPayment request with the parameters defined in $params
.
If $payline_log
isn't false
, a line is appended to the log.
See the code of the action paylinecheckout
for a list of the parameters passed in $params
.
payline_dowebpayment
returns an array with among others the fields token
and redirectURL
.
- function payline_getwebpaymentdetails($params) {
- global $payline_log;
- $sdk = payline_sdk();
- if (!$sdk) {
- return false;
- }
- $r = $sdk->getWebPaymentDetails($params);
- if ($payline_log) {
- logpayline('WebPaymentDetails', $r);
- }
- return $r;
- }
payline_getwebpaymentdetails
returns the result of a WebPayment request.
If $payline_log
isn't false
, a line is appended to the log.
$params
is an array with a field token
whose value has been returned by a previous call to the function payline_dowebpayment
.
payline_getwebpaymentdetails
returns an array with among others the fields return_code
, transaction_id
and authorization_number
.
See the Payline documentation for a list of the codes.
- function payline_amt($amt) {
- return number_format($amt, 2, '', '');
- }
- function payline_currency($cur) {
- $codes=array('EUR' => '978', 'USD' => '840', 'GPB' => '826');
- return isset($codes[$cur]) ? $codes[$cur] : '978';
- }
- function payline_language($locale) {
- $codes=array('en' => 'eng', 'fr' => 'fra');
- return isset($codes[$locale]) ? $codes[$locale] : 'eng';
- }
payline_amt
returns $amt
formatted for the SDK, i.e. $amt
with 2 decimals but no decimal point.
payline_currency
returns the code in 3 digits of the currency $cur
for the SDK.
payline_currency
returns the code for an operation in euros by default.
payline_language
returns the code in 3 letters of the language $locale
for the SDK.
payline_language
returns the code for an interface in English by default.
- function logpayline($method, $r) {
- global $payline_log;
- require_once 'log.php';
- $code=$r['result']['code'];
- $shortmsg=$r['result']['shortMessage'];
- $longmsg=$r['result']['longMessage'];
- $token = isset($r['token']) ? $r['token'] : false;
- $transaction_id = isset($r['transaction']['id']) ? $r['transaction']['id'] : false;
- $msg=array("METHOD=${method}", "CODE=${code}");
- if ($token) {
- $msg[] = "TOKEN=${token}";
- }
- if ($transaction_id) {
- $msg[] = "ID=${transaction_id}";
- }
- $msg[]="MESSAGE=${shortmsg}:${longmsg}";
- $logmsg=implode(';', $msg);
- write_log($payline_log === true ? 'payline.log' : $payline_log, $logmsg);
- }
logpayline
appends a trace line of a call to the function method
with the return values contained in the array $r
to the file payline.log of the folder log if $payline_log
is true
.
Alternatively, $payline_log
can contain the full name of another file.
Comments