-
Notifications
You must be signed in to change notification settings - Fork 11
Home
This library will help you integrate your application with Dragonpay payment gateway.
Please use latest version
Requirements:
- PHP 5.6 and above
- Dragonpay merchant account.
- PSR-4
- SoapClient Library
How to use?
- Download library using composer:
composer require crazymeeks/dragonpay v1.1.4 - After downloading, use the Dragonpay class anywhere in your code:
use Crazymeeks\Foundation\PaymentGateway\Dragonpay\Dragonpay;
Example
use Crazymeeks\Foundation\PaymentGateway\Dragonpay\Dragonpay;
class TestController
{
public function postCheckout()
{
$parameters = array(
'merchantid' => 'MERCHANTID',
'txnid' => rand(),
'amount' => 10,
'ccy' => 'PHP',
'description' => 'Test',
'email' => 'testemail@example.com',
'key' => 'YOURKEY',
);
$dragonpay = (new Dragonpay($parameters))->away();
}
}Or if you are using Laravel, you can inject the Dragonpay class directly anywhere in class constructor like in Controller.
use App\Http\Controllers\Controller;
use Crazymeeks\Foundation\PaymentGateway\Dragonpay\Dragonpay;
class CheckoutController extends Controller
{
protected $dragonpay;
public function __construct(Dragonpay $dragonpay)
{
$this->dragonpay = $dragonpay;
}
public function checkout()
{
$parameters = array(
'merchantid' => 'MERCHANTID',
'txnid' => rand(),
'amount' => 10,
'ccy' => 'PHP',
'description' => 'Test',
'email' => 'testemail@example.com',
'key' => 'YOURKEY',
);
// call the setRequestParameters() to set the Request parameters required by dragonpay
$this->dragonpay->setRequestParameters($parameters)->away();
}
}Enabling sandbox mode? Useful during testing
- By default, this library use sandbox. If you wish to use the **production **of your Dragonpay merchant account.
you can add the 3rd parameter and set it to false when you initialize the Dragonpay class, same also when
calling the setRequestParameters().
Example:
$dragonpay = (new Dragonpay($parameters, null, false))->away();
OR
$dragonpay = new Dragonpay;
$dragonpay->setRequestParameters($parameters, null, false)->away();Specifying Dragonpay payment gateway url
- If you wish to specify or change the dragonpay url, you can pass the actual url in the second parameter of Dragonpay class's __constructor or setRequestParameters(). But this is not necessary as this library automatically set the production and sandbox url by default.
$dragonpay = (new Dragonpay($parameters, 'http://test.dragonpay.com/Pay.aspx', false))->away();
OR
$dragonpay = new Dragonpay;
$dragonpay->setRequestParameters($parameters, 'http://test.dragonpay.com/Pay.aspx', false)->away();Payment Channel Filtering
Payment Channels are grouped together by type. E.g Online Banking, Over-the-Counter/ATM, etc.
You can set payment channel by calling filterPaymentChannel() method.
Example
$dragonpay = new Dragonpay;
// Over-the-Counter Banking and ATM
$dragonpay->filterPaymentChannel(2);
$dragonpay->setRequestParameters($parameters, 'http://test.dragonpay.com/Pay.aspx', false)->away();This will redirect to link like: https://gw.dragonpay.ph/Pay.aspx?merchantid=ABC&txnid=1234&…&mode=2
For the list of payment channels, see https://www.dragonpay.ph/wp-content/uploads/2014/05/Dragonpay-PS-API
Use Credit Card payment
To enable/use credit card payment, please make sure you have SoapClient installed on your system and make call to sendBillingInfo($parameter_array) method. This method will return true if success, otherwise false.
Example
$parameters = array(
'merchantid' => 'MERCHANTID',
'txnid' => rand(),
'amount' => 10,
'ccy' => 'PHP',
'description' => 'Test',
'email' => 'testemail@example.com',
'key' => 'YOURKEY',
);
$dragonpay = new Dragonpay($parameters);
// Required send billing info parameter
$sendbillinginfo_params = array(
'merchantId' => 'MERCHANTID', // A unique code assigned to Merchant
'merchantTxnId' => 'Transaction_number', // Merchant's unique transaction id
'firstName' => 'firstname', // Firstname of the customer
'lastName' => 'lastname', // Lastname of the customer
'address1' => 'address1', // Street address
'address2' => 'address2' // Village, subdivision, etc.
'city' => 'your_city', // City or Municipality
'state' => 'your_state', //State of province
'country' => 'your_country', // 2-char ISO country code(ex. PH, US, CA)
'zipCode' => 'your_zipcode', // [Optional] zip code
'telNo' => 'your_telno', // Telephone number
'email' => 'your_valid_email', // Email address of customer
);
// check if validation pass with SendBillingInfo()
if($dragonpay->sendBillingInfo($sendbillinginfo_params)){
// continue payment using credit.
$dragonpay->away();exit;
}For greater security, you can use the API using XML Web Service Model. Under this model, the parameters are not passed through browser redirect which are visible to end-users. Instead parameters are exchanged directly between the Merchant site and Payment Switch servers through SOAP calls. The PS will return a token which you will be used to redirect to PS. You can do it by:
use Crazymeeks\Foundation\PaymentGateway\Dragonpay\Token;
use Crazymeeks\Foundation\PaymentGateway\Dragonpay\Dragonpay;
$parameters = [
'merchantId' => 'SOMEMERCHANTID',
'password' => 'MERCHANTPASSWORD',
'merchantTxnId' => 'TRANS-02-' , rand(0,100),
'amount' => 10,
'ccy' => 'PHP',
'description' => 'Testing using web service',
];
$dragonpay = new Dragonpay;
// Uncomment this if you are implementing this in production
// $dragonpay->setPaymentMode('production');
$token = $dragonpay->requestToken($parameters);
// redirect to dragonpay using the return token
if ($token instanceof Token) {
$dragonpay->useToken($token)->away();exit;
}composer require crazymeeks/dragonpay v1.1.4
We take the security seriously. If you found any security issues, please create an issue or email me directly at: jeffclaud17@gmail.com
