PHP code example of simplon / payment

1. Go to this page and download the library: Download simplon/payment 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/ */

    

simplon / payment example snippets


$authPayPal = \Simplon\Payment\PayPal\Auth::init()
  ->setUsername('MERCHANT_USER')
  ->setPassword('MERCHANT_PASSWORD')
  ->setSignature('MERCHANT_SIGNATURE')
  ->setSandboxMode(TRUE); // for production = FALSE

$items = array();

// add item
$items[] = (new \Simplon\Payment\ProductItem())
  ->setRefId('12345')
  ->setName('Super Mega Pack')
  ->setDescription('500 Diamonds with 50% discount')
  ->setPrice(15)
  ->setQuantity(1)
  ->setTax(19);

// add item
$items[] = (new \Simplon\Payment\ProductItem())
  ->setName('Strong Hammer')
  ->setPrice(3.99)
  ->setQuantity(1);

// create instance of PayPalStart
$paypal = new \Simplon\Payment\PayPal\PayPalStart($authPayPal);

// request token
$paypal
  ->setOrderItemsMany($items)
  ->setUrlSuccess(URL_SUCCESS)
  ->setUrlCancel(URL_CANCEL)
  ->setCommitOnPayPal(TRUE)
  ->requestCheckoutToken();

// show token
echo $paypal->getCheckoutToken(); // prints checkoutToken

$urlPayPalLogin = $paypalSession->getUrlPayPalLogin();
echo '<a href="' . $urlPayPalLogin . '" target="_blank">' . $urlPayPalLogin . '</a>';

// auth
$authPayPal = \Simplon\Payment\PayPal\Auth::init(); // do the same as above ...

// create instance of PayPalProcess
$paypal = new \Simplon\Payment\PayPal\PayPalProcess($authPayPal);

// set received checkoutToken
$paypal->setCheckoutToken($_GET['token']);

// request checkout details based on checkoutToken
$paypal->requestGetExpressCheckoutDetails();

// get created VO
$detailsResponseVo = $paypalSession->getGetExpressCheckoutDetailsResponseVo();

// here goes code for request checkout details ...

$paypal->requestDoExpressCheckoutPayment(
  $detailsResponseVo->getPayerId(),
  $detailsResponseVo->getOrderAmount(),
  $detailsResponseVo->getCurrencyCode()
);

// resonse data are within this VO
$paymentResponseVo = $paypalSession->getDoExpressCheckoutPaymentResponseVo();

$items = [];

$items[] = (new \Simplon\Payment\ProductItem())
  ->setRefId('12345')
  ->setName('Product A')
  ->setPrice(15.99)
  ->setQuantity(1);

$items[] = (new \Simplon\Payment\ProductItem())
  ->setRefId('678910')
  ->setName('Product B')
  ->setPrice(9.99)
  ->setQuantity(1);

// create country payment methods instance
$enabledPaymentMethods = new \Simplon\Payment\Skrill\PaymentMethods\SkrillPaymentMethodsGermany();

// enable payment methods
$enabledPaymentMethods
  ->useBankSofortueberweisung()
  ->useBankOnlineBankTransfer()
  ->useCardVisa();

// request checkoutToken
$skrill = (new \Simplon\Payment\Skrill\SkrillStart())
  ->setUrlReturn(URL_RETURN)
  ->setUrlCancel(URL_CANCEL)
  ->setUrlCallback(URL_CALLBACK)
  ->setMerchantAccountEmail(MERCHANT_EMAIL)
  ->setOrderTransactionId('8473d989-4ad0-4c83-b6e3-5cc0ed74a408')
  ->setOrderCurrency('EUR')
  ->setOrderItemsMany($items)                                  // our defined items array
  ->setOrderEnabledPaymentMethods($enabledPaymentMethods)      // our enabled options
  ->addOrderCustomCallbackData('customField1', 'customValue')  // add a custom field
  ->addOrderCustomCallbackData('customField2', 'customValue')  // another custom field
  ->addOrderCustomCallbackData('customField3', 'customValue')  // and so on...
  ->requestCheckoutToken();

// get checkoutUrl
$checkoutUrl = $skrill->getCheckoutUrl();

// credentials
$merchantAccountEmail = "[MERCHANT_EMAIL]";
$merchantApiMqiPassword = "[MERCHANT_GATEWAY_PASSWORD]";
$merchantTransactionId = "[MERCHANT_TRANSACTION_ID]";

// request MQI
$checkoutQueryResponseVo = (new SkrillProcess())->getCheckoutDetailsByMerchantTransactionId(
  $merchantAccountEmail,
  $merchantApiMqiPassword,
  $merchantTransactionId
);

// $checkoutQueryResponseVo has access to the following methods:
$checkoutQueryResponseVo->getSkrillSha2Signature();
$checkoutQueryResponseVo->getSkrillMd5Signature();
$checkoutQueryResponseVo->getSkrillStatus();
$checkoutQueryResponseVo->getSkrillTransactionId();
$checkoutQueryResponseVo->getSkrillAmount();
$checkoutQueryResponseVo->getSkrillCurrency();
$checkoutQueryResponseVo->getSkrillMerchantId();
$checkoutQueryResponseVo->getPostedTransactionId();
$checkoutQueryResponseVo->getSkrillCustomerId();
$checkoutQueryResponseVo->getPostedAmount();
$checkoutQueryResponseVo->getPostedCurrency();
$checkoutQueryResponseVo->getSkrillPaymentType();
$checkoutQueryResponseVo->getPostedMerchantAccountEmail();
$checkoutQueryResponseVo->getSkrillPayFromEmail();

// fetch custom fields in case you added some to the checkout
$checkoutQueryResponseVo->getPostedCustomCallbackData();
json
{
  "": ">=5.4",
    "simplon/payment": "0.5.*"
  }
}
POST