zerosdev/durianpay-php-client

PHP client library for Durianpay.id

v1.2.1 2024-08-21 08:53 UTC

This package is auto-updated.

Last update: 2024-10-21 09:06:48 UTC


README

release language license size downloads pulls

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

  1. Run command
composer require zerosdev/durianpay-php-client

The following steps only needed if you are using Laravel

  1. Then
php artisan vendor:publish --provider="ZerosDev\Durianpay\Laravel\ServiceProvider"
  1. 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);