These sections will guide you on how to develop and test YenePay’s payment method integration with your PHP application.
Installation
Download the SDK
Go to our github page and download the latest version of our PHP SDK. Then copy the sdk folder from the downloaded directory and place it inside your PHP project folder.
Add to your project
Open your payment processor PHP class and import the SDK’s helper class and namespaces.
use YenePay\Models\CheckoutOptions;
use YenePay\Models\CheckoutItem;
use YenePay\CheckoutHelper;
require(__DIR__ .'/lib/sdk/CheckoutHelper.php');
Note: depending on your directory structure, the path to the CheckoutHelper.php file may be slightly different.
Generate checkout URL
Generate a Checkout Url using the help methods provided by the SDK library as shown below
$sellerCode = "YOUR_YENEPAY_SELLER_CODE";
$useSandbox = true;
$checkoutOptions = new CheckoutOptions($sellerCode, $useSandbox);
This will create a new instance of type CheckoutOptions and sets the UseSandbox property to true. Set this to false when on production environment.
Once you have that, set the other optional checkout options and provide the details of the order to be paid for.
$checkoutOptions.Process = CheckoutType.Express; //alternatively you can set this to CheckoutType.Cart if you are including multiple items in a single order
// These properties are optional
$checkoutOptions.SuccessReturn = "PAYMENT_SUCCESS_RETURN_URL";
$checkoutOptions.CancelReturn = "PAYMENT_CANCEL_RETURN_URL";
$checkoutOptions.IpnUrlReturn = "PAYMENT_COMPLETION_NOTIFICATION_URL";
$checkoutOptions.FailureReturn = "PAYMENT_FAILURE_RETURN_URL";
$checkoutOptions.ExpiresInDays = "NUMBER_OF_DAYS_BEFORE_THE_ORDER_EXPIRES";
$checkoutOptions.OrderId = "UNIQUE_ID_THAT_IDENTIFIES_THIS_ORDER_ON_YOUR_SYSTEM";
CheckoutItem checkoutitem = new CheckoutItem("NAME_OF_ITEM_PAID_FOR", UNIT_PRICE_OF_ITEM, QUANTITY);
string yenepayCheckoutUrl = CheckoutHelper.GetCheckoutUrl(checkoutoptions, checkoutitem);
$checkoutOrderItem = new CheckoutItem("NAME_OF_ITEM_PAID_FOR", UNIT_PRICE_OF_ITEM, QUANTITY);
$checkoutOrderItem -> ItemId = "UNIQUE_ID_FOR_THE_ITEM";
$checkoutOrderItem -> DeliveryFee = DELIVERY_FEE_IF_AVAILABLE;
$checkoutOrderItem -> Tax1 = VAT_FEE_IF_AVAILABLE;
$checkoutOrderItem -> Tax2 = TOT_FEE_IF_AVAILABLE;
$checkoutOrderItem -> Discount = DISCOUNT_AMOUNT_IF_AVAILABLE;
$checkoutOrderItem -> HandlingFee = HANDLING_FEE_IF_AVAILABLE;
$checkoutHelper = new CheckoutHelper();
$checkoutUrl = $checkoutHelper -> getSingleCheckoutUrl($checkoutOptions, $checkoutOrderItem);
If you are processing cart payment, use the getCartCheckoutUrl method instead as follows:
$checkoutUrl = $checkoutHelper -> getCartCheckoutUrl($checkoutOptions, $checkoutOrderItems);
Redirect your customer
Redirect your customer to the checkout URL generated in the step above. Your customer will then be taken to our checkout page, login with his/her YenePay account and complete the payment there. Once a payment has been successfully completed, we will send you an Instant Payment Notification (IPN) to the URL you provided on the CheckoutOptions object in the step above. When you receive this notification, you should query our IPN verification url to make sure it is an authentic notification initiated by our servers.
A sample implementation is shown below
use YenePay\Models\IPN;
use YenePay\CheckoutHelper;
require_once(__DIR__ .'/lib/sdk/CheckoutHelper.php');
require_once(__DIR__ .'/lib/sdk/Models/IPN.php');
$ipnModel = new IPN();
$ipnModel->setUseSandbox(true);
if(isset($_POST["TotalAmount"]))
$ipnModel->setTotalAmount($_POST["TotalAmount"]);
if(isset($_POST["BuyerId"]))
$ipnModel->setBuyerId($_POST["BuyerId"]);
if(isset($_POST["BuyerName"]))
$ipnModel->setBuyerName($_POST["BuyerName"]);
if(isset($_POST["TransactionFee"]))
$ipnModel->setTransactionFee($_POST["TransactionFee"]);
if(isset($_POST["MerchantOrderId"]))
$ipnModel->setMerchantOrderId($_POST["MerchantOrderId"]);
if(isset($_POST["MerchantId"]))
$ipnModel->setMerchantId($_POST["MerchantId"]);
if(isset($_POST["MerchantCode"]))
$ipnModel->setMerchantCode($_POST["MerchantCode"]);
if(isset($_POST["TransactionId"]))
$ipnModel->setTransactionId($_POST["TransactionId"]);
if(isset($_POST["Status"]))
$ipnModel->setStatus($_POST["Status"]);
if(isset($_POST["StatusDescription"]))
$ipnModel->setStatusDescription($_POST["StatusDescription"]);
if(isset($_POST["Currency"]))
$ipnModel->setCurrency($_POST["Currency"]);
if(isset($_POST["Signature"]))
$ipnModel->setSignature($_POST["Signature"]);
$helper = new CheckoutHelper();
if ($helper->isIPNAuthentic($ipnModel))
echo 'Success!';
else
echo 'Fail';
For a more concrete example, please have a look at our sampleshopapplication on our github page that shows how you can do the integration on your PHP based application.