1
32

payline

  1. require_once 'payline.inc';
  2. require_once 'vendor/autoload.php';
  3.  
  4. use \Payline\PaylineSDK;

Loads the configuration file. Initializes the access to the code of the class PaylineSDK.

  1. function payline_sdk() {
  2.     global $payline_merchant_id, $payline_access_key;
  3.     global $payline_proxy_host, $payline_proxy_port, $payline_proxy_login, $payline_proxy_password;
  4.     global $payline_context;
  5.  
  6.     static $sdk=null;
  7.  
  8.     if (!$sdk) {
  9.         $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);
  10.     }
  11.  
  12.     return $sdk;
  13. }

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.

  1. function payline_dowebpayment($params) {
  2.     global $payline_log;
  3.  
  4.     $sdk = payline_sdk();
  5.  
  6.     if (!$sdk) {
  7.         return false;
  8.     }
  9.  
  10.     $r = $sdk->doWebPayment($params);
  11.  
  12.     if ($payline_log) {
  13.         logpayline('WebPayment', $r);
  14.     }
  15.  
  16.     return $r;
  17. }

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.

  1. function payline_getwebpaymentdetails($params) {
  2.     global $payline_log;
  3.  
  4.     $sdk = payline_sdk();
  5.  
  6.     if (!$sdk) {
  7.         return false;
  8.     }
  9.  
  10.     $r = $sdk->getWebPaymentDetails($params);
  11.  
  12.     if ($payline_log) {
  13.         logpayline('WebPaymentDetails', $r);
  14.     }
  15.  
  16.     return $r;
  17. }

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.

  1. function payline_amt($amt) {
  2.     return number_format($amt, 2, '', '');
  3. }
  4.  
  5. function payline_currency($cur) {
  6.     $codes=array('EUR' => '978', 'USD' => '840', 'GPB' => '826');
  7.  
  8.     return isset($codes[$cur]) ? $codes[$cur] : '978';
  9. }
  10.  
  11. function payline_language($locale) {
  12.     $codes=array('en' => 'eng', 'fr' => 'fra');
  13.  
  14.     return isset($codes[$locale]) ? $codes[$locale] : 'eng';
  15. }

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.

  1. function logpayline($method, $r) {
  2.     global $payline_log;
  3.  
  4.     require_once 'log.php';
  5.  
  6.     $code=$r['result']['code'];
  7.     $shortmsg=$r['result']['shortMessage'];
  8.     $longmsg=$r['result']['longMessage'];
  9.  
  10.     $token = isset($r['token']) ? $r['token'] : false;
  11.     $transaction_id = isset($r['transaction']['id']) ? $r['transaction']['id'] : false;
  12.  
  13.     $msg=array("METHOD=${method}", "CODE=${code}");
  14.     if ($token) {
  15.         $msg[] = "TOKEN=${token}";
  16.     }
  17.     if ($transaction_id) {
  18.         $msg[] = "ID=${transaction_id}";
  19.     }
  20.     $msg[]="MESSAGE=${shortmsg}:${longmsg}";
  21.  
  22.     $logmsg=implode(';', $msg);
  23.  
  24.     write_log($payline_log === true ? 'payline.log' : $payline_log, $logmsg);
  25. }

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.

SEE ALSO

Payline, log, paypal

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].