Moncash Rest Api With PHP: Documentation
Moncash Rest Api With PHP: Documentation
PHP
Documentation
INTRODUCTION 2
COMPLETE CODE 4
1
Introduction
Moncash REST API is a simple way of integrating the payment gateway into your site to
take payments. In this article we're going to look at a simple example that will use
Moncash SDK to take payments using PHP.
2
1. Auto load the SDK Package. This will include all the files and classes to your
autoloader. Please note, if you downloaded the SDK directly, replace vendor by
the complete path to the autoloader from the package.
<?php
...
$client = "client id";
$secret = "client secret";
$configArray = Configuration::getSandboxConfigs(); // Configuration::getProdConfigs()
for live
$credential = new Credentials($client, $secret, $configArray);
// Create payment
$amount = 201;//amount in HTG
$orderId = "979879799798";; //may be your cart Id
$theOrder = new Order( $orderId, $amount );
$paymentObj = PaymentMaker::makePaymentRequest($theOrder, $credential,
$configArray);
//This method return the payment gateway url
echo $paymentObj->getRedirect();
3
4. Capture payment using the transactionId
echo $transactionDetails->getPayment()->getReference();
echo $transactionDetails->getPayment()->getTransactionId();
echo $transactionDetails->getPayment()->getCost();
echo $transactionDetails->getPayment()->getMessage();
echo $transactionDetails->getPayment()->getPayer();
echo date('D M d Y', $transactionDetails->getTimestamp()/1000);
echo $transactionDetails->getPayment()->getReference();
echo $transactionDetails->getPayment()->getTransactionId();
echo $transactionDetails->getPayment()->getCost();
echo $transactionDetails->getPayment()->getMessage();
echo $transactionDetails->getPayment()->getPayer();
echo date('D M d Y', $transactionDetails->getTimestamp()/1000);
Complete code
The complete example code for the integration described in this post can be found on GitHub. Check it out,
download and play with it. Hopefully this really simple example will get you started with integrating Moncash
into your site.