PHP code example of dotlines-io / foster

1. Go to this page and download the library: Download dotlines-io/foster 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');

/* Start to develop here. Best regards https://php-download.com/ */

    

dotlines-io / foster example snippets


/**
 * ******************************************************
 * ******************* Charge Request *******************
 * ******************************************************
 */

$charge_request_url = "<SERVER_URL>/fosterpayments/paymentrequest.php"; // Contact Foster Payments for it
$mcnt_AccessCode = '';          // Contact Foster Payments for it
$mcnt_ShortName = "";           // Contact Foster Payments for it
$mcnt_ShopId = '';              // Contact Foster Payments for it
$secretkey = "";                // Contact Foster Payments for it

$mcnt_TxnNo = '';               // Mandatory | Unique | Max: 32 Char 
$mcnt_Amount = 100;             // Mandatory | The total amount payable | Decimal
$mcnt_Currency = 'BDT';         // Mandatory | 3 Letter currency code  
$cust_InvoiceTo = '';           // Mandatory | Customer ID
$cust_CustomerServiceName = ''; // Mandatory | Service or Items sold
$cust_CustomerName = '';        // Mandatory | Customer ID
$cust_CustomerEmail = '';       // Mandatory | Customer Email
$cust_CustomerAddress = '';     // Mandatory | Customer Address
$cust_CustomerContact = '';     // Mandatory | Customer Contact no
$cust_CustomerCity = '';        // Mandatory | Customer City
$cust_CustomerState = '';       // Optional | Customer State
$cust_CustomerPostcode = '';    // Optional
$cust_CustomerCountry = '';     // Mandatory | Customer Country
$cust_Billingaddress = '';      // Mandatory | Customer Billing Address
$cust_ShippingAddress = '';     // Mandatory | Customer Shipping Address
$cust_orderitems = '';          // Mandatory | Customer ordered itme name, no, etc.
$success_url = '';              // Mandatory | Customer redirection URL after successful payment 
$cancel_url = '';               // Mandatory | Customer redirection URL after payment is canceled
$fail_url = '';                 // Mandatory | Customer redirection URL after payment failure
$merchentdomainname = '';       // Mandatory | Domain Name
$merchentip = '';               // Mandatory | Domain IP
$merchentip = '';               // Mandatory | Domain IP
$gateway = '';                  // Optional  | Gateway name
$card_type = '';                // Optional  | Card Type


$chargeRequest = \Dotlines\Foster\ChargeRequest::getInstance($charge_request_url, $mcnt_AccessCode, $mcnt_ShortName, $mcnt_ShopId, $secretkey,
    $mcnt_TxnNo, $mcnt_Amount, $mcnt_Currency, $cust_InvoiceTo, $cust_CustomerServiceName, $cust_CustomerName, $cust_CustomerEmail, $cust_CustomerAddress,
    $cust_CustomerContact, $cust_CustomerCity, $cust_CustomerState, $cust_CustomerPostcode, $cust_CustomerCountry, $cust_Billingaddress, $cust_ShippingAddress,
    $cust_orderitems, $success_url, $cancel_url, $fail_url, $merchentdomainname, $merchentip, $gateway, $card_type);
echo json_encode($chargeRequest->send()) . '<br/>';

/**
 * Success Charge Request Response looks like below.
 * You must store "payment_id" and redirect the user to the "redirect_url" for payment.
 * {
 *  "status": "200",
 *  "message": "Your Request Successfully received",
 *  "data": {
 *      "payment_id": "Testdc400a5.49862879-93218-nYaHX",
 *      "redirect_url": "https://demo.fosterpayments.com.bd/short/redirect.php",
 *      "merchant_ShopId": "6"
 *  }
 * }
 * Fail response only contains status > 200
 */


/**
 * ******************************************************
 * ******************* Status Request *******************
 * ******************************************************
 */

$status_url = "<SERVER_URL>/fosterpayments/TransactionStatus/txstatus.php";
$mcnt_TxnNo = '';   // Transaction No provided during payment request initiation
$secretkey = '';    // Secret key provided by admin 

$statusRequest = \Dotlines\Foster\StatusRequest::getInstance($status_url, $mcnt_TxnNo, $secretkey);
echo json_encode($statusRequest->send()) . '<br/>';

/**
 * Status Request Response looks like below:
 *[
 * {
 *      "MerchantTxnNo":"XXXXXXXXXXXXX",
 *      "TxnResponse":2,
 *      "TxnAmount":"1020.00",
 *      "Currency":"BDT",
 *      "ConvertionRate":"1",
 *      "OrderNo":"1803600769",
 *      "fosterid":"BUP8d8b615.97386539",
 *      "hashkey":"b3bceae17f843a910a4e295feed349a4",
 *      "message":"Transaction Successfully."
 *  }
 * ]
 * Fail response only contains status > 200
 */