PHP code example of kenng / ipay88
1. Go to this page and download the library: Download kenng/ipay88 library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once ('vendor/autoload.php' );
kenng / ipay88 example snippets
class Payment {
protected $_merchantCode;
protected $_merchantKey;
public function __construct ()
{
parent ::__construct();
$this ->_merchantCode = env(IPAY88_MERCHANT_CODE, 'xxxxxx' );
$this ->_merchantKey = env(IPAY88_MERCHANT_KEY, 'xxxxxxxxx' );
$this ->responseUrl = 'http://your-website.com/url-redirected-after-payment' ;
$this ->backendUrl = 'http://your-website.com/backup-url-if-responseurl-fails' ;
}
public function index ()
{
$iRequest = new \IPay88\Payment\Request($this ->_merchantKey);
$this ->_data = array (
'MerchantCode' => $iRequest->setMerchantCode($this ->_merchantCode),
'PaymentId' => $iRequest->setPaymentId(1 ),
'RefNo' => $iRequest->setRefNo('EXAMPLE0001' ),
'Amount' => $iRequest->setAmount('1.00' ),
'Currency' => $iRequest->setCurrency('MYR' ),
'ProdDesc' => $iRequest->setProdDesc('Testing' ),
'UserName' => $iRequest->setUserName('Your name' ),
'UserEmail' => $iRequest->setUserEmail('email@example.com' ),
'UserContact' => $iRequest->setUserContact('0123456789' ),
'Remark' => $iRequest->setRemark('Some remarks here..' ),
'Lang' => $iRequest->setLang('UTF-8' ),
'Signature' => $iRequest->getSignature(),
'SignatureType' => $iRequest->setSignatureType('SHA256' ),
'ResponseURL' => $iRequest->setResponseUrl('http://example.com/response' ),
'BackendURL' => $iRequest->setBackendUrl('http://example.com/backend' )
);
IPay88\Payment\Request::make($this ->_merchantKey, $this ->_data);
}
public function getForAPI ()
{
$iRequest = new \IPay88\Payment\Request(
$this ->_merchantKey,
$this ->_merchantCode,
$this ->responseUrl,
$this ->backendUrl,
);
return $iRequest->dataForAPI(
$this ->_merchantCode,
'Reference Number or unique order number' ,
'0.50' ,
'MYR' ,
'product description' ,
'customer name' ,
'customer email' ,
'customer contact' ,
'merchant remark' ,
'UTF-8' ,
);
}
public function response ()
{
$response = (new IPay88\Payment\Response)->init($this ->_merchantCode);
return $response;
}
}