zerosdev / durianpay-php-client
PHP client library for Durianpay.id
v1.2.1
2024-08-21 08:53 UTC
Requires
- php: >=7.0.0
- ext-json: *
- guzzlehttp/guzzle: ^6.5|^7.0
README
About
This library give you an easy way to call DurianPay API in elegant code style. Example :
Durianpay::orders()->fetch();
Durianpay::payments() ->setType('VA') ->setRequest(function (Request $request) { $request->setOrderId('ord_JGytr64yGj8') ->setBankCode('XXX') ->setName('Nama Pelanggan') ->setAmount(10000); }) ->charge()
Installation
- Run command
composer require zerosdev/durianpay-php-client
The following steps only needed if you are using Laravel
- Then
php artisan vendor:publish --provider="ZerosDev\Durianpay\Laravel\ServiceProvider"
- Edit config/durianpay.php and put your API credentials
Usage
Laravel
<?php namespace App\Http\Controllers; use Durianpay; use ZerosDev\Durianpay\Components\Customer\Customer; use ZerosDev\Durianpay\Components\Customer\Adress; use ZerosDev\Durianpay\Components\Customer\Info; use ZerosDev\Durianpay\Components\Items; use ZerosDev\Durianpay\Components\Metadata; class YourController extends Controller { public function index() { $order = Durianpay::orders() ->setAmount(10000) ->setPaymentOption('full_payment') ->setCurrency('IDR') ->setOrderRefId("123456") ->setCustomer(function (Customer $customer) { $customer->setEmail('email@customer.com') ->setAddress(function (Address $address) { $address->setReceiverName('Nama Penerima'); }); }) ->setItems(function (Items $items) { $items->add('Nama Produk', 10000, 1, 'https://google.com/product.jpg'); }) ->setMetadata(function (Metadata $metadata) { $metadata->setMerchantRef('123456789'); }) ->create(); dd($order); } }
Non-Laravel
<?php require 'path/to/your/vendor/autoload.php'; use ZerosDev\Durianpay\Client; use ZerosDev\Durianpay\Components\Customer\Customer; use ZerosDev\Durianpay\Components\Customer\Adress; use ZerosDev\Durianpay\Components\Customer\Info; use ZerosDev\Durianpay\Components\Items; use ZerosDev\Durianpay\Components\Metadata; $durianpay = new Client('your_api_key_here'); $order = $durianpay->orders() ->setAmount(10000) ->setPaymentOption('full_payment') ->setCurrency('IDR') ->setOrderRefId("123456") ->setCustomer(function (Customer $customer) { $customer->setEmail('email@customer.com') ->setAddress(function (Address $address) { $address->setReceiverName('Nama Penerima'); }); }) ->setItems(function (Items $items) { $items->add('Nama Produk', 10000, 1, 'https://google.com/product.jpg'); }) ->setMetadata(function (Metadata $metadata) { $metadata->setMerchantRef('123456789'); }) ->create(); print_r($order);