xendit/xendit-php-clients

This package is abandoned and no longer maintained. The author suggests using the xendit-php package instead.
There is no license information available for the latest version (2.0.2) of this package.

PHP clients for Xendit API

2.0.2 2020-02-12 02:57 UTC

README

This library is the abstraction of Xendit API for access from applications written with PHP.

Documentation

For the API documentation, check Xendit API Reference.

Installation

Install xendit-php-clients with composer by following command:

composer require xendit/xendit-php

or add it manually in your composer.json file.

Update from v1.4.0 to v2.0.0

To update xendit-php-clients with composer, use the following command:

composer update xendit/xendit-php

To migrate, see MIGRATE.md for more information.

Usage

Configure package with your account's secret key obtained from Xendit Dashboard.

Xendit::setApiKey('secretKey');

See example codes for more details.

Methods' Signature and Examples

Balance

Get Balance

\Xendit\Balance::getBalance(string $account_type);

Usage example:

$getBalance = \Xendit\Balance::getBalance('CASH');
var_dump($getBalance);

Cards

Create Charge

\Xendit\Cards::create(array $params);

Usage example:

$params = [
    'token_id' => '5e2e8231d97c174c58bcf644',
    'external_id' => 'card_' . time(),
    'authentication_id' => '5e2e8658bae82e4d54d764c0',
    'amount' => 100000,
    'card_cvn' => '123',
    'capture' => false
];

$createCharge = \Xendit\Cards::create($params);
var_dump($createCharge);

Reverse Authorization

\Xendit\Cards::reverseAuthorization(string $id, array $params);

Usage example:

$id = 'charge-id';
$params = ['external_id' => 'ext-id'];

$reverseAuth = \Xendit\Cards::reverseAuthorization(
    $id,
    $params
);
var_dump($reverseAuth);

Capture Charge

\Xendit\Cards::capture(string $id, array $params);

Usage example:

$id = 'charge-id';
$params = ['amount' => 100000];

$captureCharge = \Xendit\Cards::capture($id, $params);
var_dump($captureCharge);

Get Charge

\Xendit\Cards::retrieve(string $id);

Usage example:

$id = 'charge-id';

$getCharge = \Xendit\Cards::retrieve($id);
var_dump($getCharge);

Create Refund

\Xendit\Cards::createRefund(string $id, array $params);

Usage examples

Without idempotency key:

$params = [
    'external_id' => 'ext-id',
    'amount' => 20000
];

$refund = \Xendit\Cards::createRefund($id, $params);
var_dump($refund);

With idempotency key:

$params = [
    'external_id' => 'ext-id',
    'amount' => 20000,
    'X-IDEMPOTENCY-KEY' => 'unique-id'
];

$refund = \Xendit\Cards::createRefund($id, $params);
var_dump($refund);

Cardless Credit

Create Cardless Credit Payment

\Xendit\CardlessCredit::create(array $params);

Usage example:

$params = [
    'cardless_credit_type' => 'KREDIVO',
    'external_id' => 'test-cardless-credit-02',
    'amount' => 800000,
    'payment_type' => '3_months',
    'items' => [
        [
            'id' => '123123',
            'name' => 'Phone Case',
            'price' => 200000,
            'type' => 'Smartphone',
            'url' => 'http=>//example.com/phone/phone_case',
            'quantity' => 2
        ],
        [
            'id' => '234567',
            'name' => 'Bluetooth Headset',
            'price' => 400000,
            'type' => 'Audio',
            'url' => 'http=>//example.com/phone/bluetooth_headset',
            'quantity' => 1
        ]
    ],
    'customer_details' => [
        'first_name' => 'customer first name',
        'last_name' => 'customer last name',
        'email' => 'customer@yourwebsite.com',
        'phone' => '081513114262'
    ],
    'shipping_address' => [
        'first_name' => 'first name',
        'last_name' => 'last name',
        'address' => 'Jalan Teknologi No. 12',
        'city' => 'Jakarta',
        'postal_code' => '12345',
        'phone' => '081513114262',
        'country_code' => 'IDN'
    ],
    'redirect_url' => 'https://example.com',
    'callback_url' => 'http://example.com/callback-cardless-credit'
];

$createPayment = \Xendit\CardlessCredit::create($params);
var_dump($createPayment);

Disbursements

Create Disbursement

\Xendit\Disbursements::create(array $params);

Usage examples

Without idempotency key:

$params = [
    'external_id' => 'disb-12345678',
    'amount' => 15000,
    'bank_code' => 'BCA',
    'account_holder_name' => 'Joe',
    'account_number' => '1234567890',
    'description' => 'Disbursement from Example'
];

$createDisbursements = \Xendit\Disbursements::create($params);
var_dump($createDisbursements);

With idempotency key:

$params = [
    'external_id' => 'disb-12345678',
    'amount' => 15000,
    'bank_code' => 'BCA',
    'account_holder_name' => 'Joe',
    'account_number' => '1234567890',
    'description' => 'Disbursement from Example',
    'X-IDEMPOTENCY-KEY' => 'unique-id'
];

$createDisbursements = \Xendit\Disbursements::create($params);
var_dump($createDisbursements);

Create Batch Disbursement

\Xendit\Disbursements::createBatch(array $params);

Usage example:

$batch_params = [
    'reference' => 'disb_batch-12345678',
    'disbursements' => [
        [
            'amount' => 20000,
            'bank_code' => 'BCA',
            'bank_account_name' => 'Fadlan',
            'bank_account_number' => '1234567890',
            'description' => 'Batch Disbursement',
            'external_id' => 'disbursement-1'
        ],
        [
            'amount' => 30000,
            'bank_code' => 'MANDIRI',
            'bank_account_name' => 'Lutfi',
            'bank_account_number' => '1234567891',
            'description' => 'Batch Disbursement with email notifications',
            'external_id' => 'disbursement-2',
            'email_to' => ['test+to@xendit.co'],
            'email_cc' => ['test+cc@xendit.co'],
            'email_bcc' => ['test+bcc1@xendit.co', 'test+bcc2@xendit.co']
        ]
    ]
];

$createBatchDisbursements = \Xendit\Disbursements::createBatch($batch_params);
var_dump($createBatchDisbursements);

Get Disbursement by ID

\Xendit\Disbursements::retrieve(string $id);

Usage example:

$id = 'disbursements-id';
$getDisbursements = \Xendit\Disbursements::retrieve($id);
var_dump($getDisbursements);

Get Disbursement by External ID

\Xendit\Disbursements::retrieveExternal(string $external_id);

Usage example:

$external_id = 'disbursements-ext-id';
$getDisbursementsByExt = \Xendit\Disbursements::retrieveExternal($external_id);
var_dump($getDisbursementsByExt);

Get Disbursement Available Banks

\Xendit\Disbursements::getAvailableBanks();

Usage example:

$getDisbursementsBanks = \Xendit\Disbursements::getAvailableBanks();
var_dump($getDisbursementsBanks);

E-Wallets

Create Payment

\Xendit\EWallets::create(array $params);

To create payment, each e-wallet has its own required params. For more information, please check Xendit API Reference - E-Wallets.

OVO
$ovoParams = [
    'external_id' => 'demo_' . time(),
    'amount' => 32000,
    'phone' => '081298498259',
    'ewallet_type' => 'OVO'
];

$createOvo = \Xendit\EWallets::create($ovoParams);
var_dump($createOvo);
DANA
$danaParams = [
    'external_id' => 'demo_' . time(),
    'amount' => 32000,
    'phone' => '081298498259',
    'expiration_date' => '2020-02-20T00:00:00.000Z',
    'callback_url' => 'https://my-shop.com/callbacks',
    'redirect_url' => 'https://my-shop.com/home',
    'ewallet_type' => 'DANA'
];

$createDana = \Xendit\EWallets::create($danaParams);
var_dump($createDana);
LinkAja
$linkajaParams = [
    'external_id' => 'demo_' . time(),
    'amount' => 32000,
    'phone' => '081298498259',
    'items' => [
        [
            'id' => '123123',
            'name' => 'Phone Case',
            'price' => 100000,
            'quantity' => 1
        ],
        [
            'id' => '345678',
            'name' => 'Powerbank',
            'price' => 200000,
            'quantity' => 1
        ]
    ],
    'callback_url' => 'https =>//yourwebsite.com/callback',
    'redirect_url' => 'https =>//yourwebsite.com/order/123',
    'ewallet_type' => 'LINKAJA'
];

$createLinkaja = \Xendit\EWallets::create($linkajaParams);
var_dump($createLinkaja);

Get Payment Status

\Xendit\EWallets::getPaymentStatus(string $external_id, string $ewallet_type);

Usage example:

$external_id = 'external-ID';
$ewallet_type = 'OVO';
$getPayments = \Xendit\EWallets::getPaymentStatus($external_id, $ewallet_type);

Invoice

Create Invoice

\Xendit\Invoice::create(array $params);

Usage example:

$params = ['external_id' => 'demo_147580196270',
    'payer_email' => 'sample_email@xendit.co',
    'description' => 'Trip to Bali',
    'amount' => 32000
];

$createInvoice = \Xendit\Invoice::create($params);
var_dump($createInvoice);

Get Invoice

\Xendit\Invoice::retrieve(string $id);

Usage example:

$id = 'invoice-id';
$getInvoice = \Xendit\Invoice::retrieve($id);
var_dump($getInvoice);

Get All Invoice

\Xendit\Invoice::retrieveAll();

Usage example:

$getAllInvoice = \Xendit\Invoice::retrieveAll();
var_dump(($getAllInvoice));

Expire Invoice

\Xendit\Invoice::expireInvoice(string $id);

Usage example:

$id = 'invoice-id';
$expireInvoice = \Xendit\Invoice::expireInvoice($id);
var_dump($expireInvoice);

Payouts

Create Payout

\Xendit\Payouts::create(array $params);

Usage example:

$params = [
    'external_id' => 'payouts-123456789',
    'amount' => 50000
];

$createPayout = \Xendit\Payouts::create($params);
var_dump($createPayout);

Get Payout

\Xendit\Payouts::retrieve(string $id);

Usage example:

$id = 'payout-id';

$getPayout = \Xendit\Payouts::retrieve($id);
var_dump($getPayout);

Void Payout

\Xendit\Payouts::void(string $id);

Usage example:

$id = 'payout-id';

$voidPayout = \Xendit\Payouts::void($id);
var_dump($voidPayout);

Recurring Payments

Create a Recurring Payment

\Xendit\Recurring::create(array $params);

Usage example:

$params = [
    'external_id' => 'demo_147580196270',
    'payer_email' => 'sample_email@xendit.co',
    'description' => 'Trip to Bali',
    'amount' => 32000,
    'interval' => 'MONTH',
    'interval_count' => 1
];

$createRecurring = \Xendit\Recurring::create($params);
var_dump($createRecurring);

Get a Recurring Payment

\Xendit\Recurring::retrieve(string $id);

Usage example:

$id = 'recurring-payment-id';

$getRecurring = \Xendit\Recurring::retrieve($id);
var_dump($getRecurring);

Edit Recurring Payment

\Xendit\Recurring::update(string $id, array $params);

Usage example:

$id = 'recurring-payment-id';
$params = ['amount' => 10000];

$editRecurring = \Xendit\Recurring::update($id, $params);
var_dump($editRecurring);

Stop Recurring Payment

\Xendit\Recurring::stop(string $id);

Usage example:

$id = 'recurring-payment-id';

$stopRecurring = \Xendit\Recurring::stop($id);
var_dump($stopRecurring);

Pause Recurring Payment

\Xendit\Recurring::pause(string $id);

Usage example:

$id = 'recurring-payment-id';

$pauseRecurring = \Xendit\Recurring::pause($id);
var_dump($pauseRecurring);

Resume Recurring Payment

\Xendit\Recurring::resume(string $id);

Usage example:

$id = 'recurring-payment-id';

$resumeRecurring = \Xendit\Recurring::resume($id);
var_dump($resumeRecurring);

Retail Outlets

Create Fixed Payment Code

\Xendit\Retail::create(array $params);

Usage example:

$params = [
    'external_id' => 'TEST-123456789',
    'retail_outlet_name' => 'ALFAMART',
    'name' => 'JOHN DOE',
    'expected_amount' => 25000
];

$createFPC = \Xendit\Retail::create($params);
var_dump($createFPC);

Update Fixed Payment Code

\Xendit\Retail::update(string $id, array $params);

Usage example:

$id = 'FPC-id';
$updateParams = ['expected_amount' => 20000];

$updateFPC = \Xendit\Retail::update($id, $updateParams);
var_dump($updateFPC);

Get Fixed Payment Code

\Xendit\Retail::retrieve(string $id);

Usage example:

$id = 'FPC-id';
$getFPC = \Xendit\Retail::retrieve($id);
var_dump($getFPC);

Virtual Accounts

Create Fixed Virtual Account

\Xendit\VirtualAccounts::create(array $params);

Usage example:

$params = ["external_id" => "VA_fixed-12341234",
   "bank_code" => "MANDIRI",
   "name" => "Steve Wozniak"
];

$createVA = \Xendit\VirtualAccounts::create($params);
var_dump($createVA);

Get Virtual Account Bank

\Xendit\VirtualAccounts::getVABanks();

Usage example:

$getVABanks = \Xendit\VirtualAccounts::getVABanks();
var_dump($getVABanks);

Get Fixed Virtual Account

\Xendit\VirtualAccounts::retrieve(string $id);

Usage example:

$id = 'VA-id';
$getVA = \Xendit\VirtualAccounts::retrieve($id);
var_dump($getVA);

Update Fixed Virtual Account

\Xendit\VirtualAccounts::update(string $id, array $params);

Usage example:

$id = 'VA-id';
$updateParams = ["suggested_amount" => 1000];

$updateVA = \Xendit\VirtualAccounts::update($id, $updateParams);
var_dump($updateVA);

Get Fixed Virtual Account Payment

\Xendit\VirtualAccounts::getFVAPayment(string $paymentID);

Usage example:

$paymentID = 'payment-ID';
$getFVAPayment = \Xendit\VirtualAccounts::getFVAPayment($paymentID);
var_dump($getFVAPayment);

Contributing

For any requests, bugs, or comments, please open an issue or submit a pull request.

Tests

Running test suite:

vendor\bin\phpunit tests

Running examples:

php examples\InvoiceExample.php

There is a pre-commit hook to run phpcs and phpcbf. Please make sure they passed before making commits/pushes.