ryuamy / trs-emas-php
Treasury PHP API Third Party Library
dev-master
2021-07-22 10:21 UTC
Requires
- php: >=7.2.0
This package is auto-updated.
Last update: 2024-11-22 18:12:22 UTC
README
using Treasury API v2.2, please make sure Treasury API version you gonna use and read API procedure below for flow of registration and transaction.
Instalation
Install package with composer by following command:
composer require ryuamy/trs-emas-php
Call Package
Add following code on your project:
use Ryuamy\TrsEmas;
Usages
TrsEmas\Class::function( $productionFlag, $bodyParameters, $token );
Parameters detail:
- $productionFlag: if set to true, package will hit Treasury production API, false to hit Treasury staging API. Mandatory on all class.
- $bodyParameters: request body parameter. Optional on some Class.
- $token: bearer token from client login (for User Register) or user login (for the rest of API). Optional on some class.
Look at example to see parameter requirement on each class.
Example
Authentication
Client Login
$bodyParameters = [ 'client_id' => '(Treasury client id)', 'client_secret' => '(Treasury client secret)', ]; $Tresury = TrsEmas\Authentication::loginClient( true, $bodyParameters );
User Register
$bodyParameters = [ 'name' => 'Ryu Amy', 'email' => 'ryuamy.mail@gmail.com', 'password' => '(My Password)', 'password_confirmation' => '(My Password)', 'gender' => 'female', 'birthday' => '1991-01-01', 'referral_code' => '', 'phone' => '081312345678', 'security_question' => 'KQxz9YXazA14VEO', 'security_question_answer' => 'Sebastian Michaelis', 'selfie_scan' => '/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQ...', 'id_card_scan' => '/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQ...', 'owner_name' => 'Ryu Amy', 'account_number' => '123456', 'bank_code' => 'string', 'branch' => 'Jakarta', 'customer_concern' => false ]; $Tresury = TrsEmas\Authentication::register( true, $bodyParameters, '(Bearer Token)' );
Notes:
- Bearer Token get from Client Login response
- security_question value using Security Question response
- bank_code value using Bank List response
User Login
$bodyParameters = [ 'client_id' => '(Treasury client id)', 'client_secret' => '(Treasury client secret)', 'email' => 'ryuamy.mail@gmail.com', 'password' => '(My Password)', ]; $Tresury = TrsEmas\Authentication::login( true, $bodyParameters );
Transaction
Gold Rate
$bodyParameters = [ 'start_date' => '2021-03-03 09:00:00', 'end_date' => '2021-03-03 10:00:00' ]; $Tresury = TrsEmas\Transaction::goldRate( true, $bodyParameters, '(Bearer Token)' );
Calculate Buy Amount Type Currency
$bodyParameters = [ 'amount_type' => 'currency', 'amount' => 400000, 'payment_method' => 'bca', ]; $Tresury = TrsEmas\Transaction::calculateBuy( true, $bodyParameters, '(Bearer Token)' );
Calculate Buy Amount Type Gold
$bodyParameters = [ 'amount_type' => 'gold', 'amount' => 0.582, 'payment_method' => 'bca', ]; $Tresury = TrsEmas\Transaction::calculateBuy( true, $bodyParameters, '(Bearer Token)' );
Calculate Sell Amount Type Currency
$bodyParameters = [ 'amount_type' => 'currency', 'amount' => 50000, ]; $Tresury = TrsEmas\Transaction::calculateSell( true, $bodyParameters, '(Bearer Token)' );
Calculate Sell Amount Type Gold
$bodyParameters = [ 'amount_type' => 'gold', 'amount' => 0.015, ]; $Tresury = TrsEmas\Transaction::calculateSell( true, $bodyParameters, '(Bearer Token)' );
Calculate Buy Amount Type Currency For Partner
$bodyParameters = [ 'amount_type' => 'currency', 'amount' => 400000, ]; $Tresury = TrsEmas\Transaction::calculateBuyPartner( true, $bodyParameters, '(Bearer Token)' );
Calculate Buy Amount Type Gold For Partner
$bodyParameters = [ 'amount_type' => 'gold', 'amount' => 0.582, ]; $Tresury = TrsEmas\Transaction::calculateBuyPartner( true, $bodyParameters, '(Bearer Token)' );
Calculate Sell Amount Type Currency For Partner
$bodyParameters = [ 'amount_type' => 'currency', 'amount' => 50000, ]; $Tresury = TrsEmas\Transaction::calculateSellPartner( true, $bodyParameters, '(Bearer Token)' );
Calculate Sell Amount Type Gold For Partner
$bodyParameters = [ 'amount_type' => 'gold', 'amount' => 0.015, ]; $Tresury = TrsEmas\Transaction::calculateSellPartner( true, $bodyParameters, '(Bearer Token)' );
Payment Method
$Tresury = TrsEmas\Transaction::paymentMethod( true, '(Bearer Token)' );
Buy Gold
$bodyParameters = [ 'unit' => 1.8766253, 'total' => 796169, 'payment_channel' => 'BRIN', 'latitude' => '-6.914744', 'longitude' => '107.609810' ]; $Tresury = TrsEmas\Transaction::buy( true, $bodyParameters, '(Bearer Token)' );
Buy Gold For Partner
$bodyParameters = [ 'invoice_number' => 'TRS42154451', 'unit' => 1.8766253, 'total' => 796169, 'payment_channel' => 'BRIN', 'latitude' => '-6.914744', 'longitude' => '107.609810' ]; $Tresury = TrsEmas\Transaction::buyPartner( true, $bodyParameters, '(Bearer Token)' );
Apply Voucer Buy Gold
$bodyParameters = [ 'code' => 'TRSVCR1', ]; $Tresury = TrsEmas\Transaction::applyVoucher( true, $bodyParameters, '(Bearer Token)' );
Payment Notify For Partner
$bodyParameters = [ 'invoice_number' => 'TRS42154451', 'payment_note' => 'Payment to BRI' ]; $Tresury = TrsEmas\Transaction::paymentNotify( true, $bodyParameters, '(Bearer Token)' );
Sell Gold
$bodyParameters = [ 'total' => 31587, 'unit' => 0.0432, 'latitude' => '-6.914744', 'longitude' => '107.609810' ]; $Tresury = TrsEmas\Transaction::sell( true, $bodyParameters, '(Bearer Token)' );
Minting
Minting Partner
$Tresury = TrsEmas\Minting::mintingPartner( true, '(Bearer Token)' );
Minting Fee
$bodyParameters = [ 'minting_partner' => 'x6A3lOoJXL59zDd' ]; $Tresury = TrsEmas\Minting::mintingFee( true, $bodyParameters, '(Bearer Token)' );
Notes:
- minting_partner value using Minting Partner response
Minting Piece
$bodyParameters = [ 'minting_partner' => 'x6A3lOoJXL59zDd' ]; $Tresury = TrsEmas\Minting::mintingPiece( true, $bodyParameters, '(Bearer Token)' );
Notes:
- minting_partner value using Minting Partner response
Minting Shipping
$bodyParameters = [ 'minting_partner' => 'x6A3lOoJXL59zDd' ]; $Tresury = TrsEmas\Minting::mintingShipping( true, $bodyParameters, '(Bearer Token)' );
Notes:
- minting_partner value using Minting Partner response
Calculate Minting
$bodyParameters = [ 'minting_partner' => 'x6A3lOoJXL59zDd', 'minting_fee' => 'JGYPjrXW7XDw2mE', 'minting_piece' => 'KQxz9YXazA14VEO', 'minting_shipping' => '7Jb1VXLrzpm69xv' ]; $Tresury = TrsEmas\Minting::calculateMinting( true, $bodyParameters, '(Bearer Token)' );
Notes:
- minting_partner value using Minting Partner response
- minting_fee value using Minting Fee response
- minting_piece value using Minting Piece response
- minting_shipping value using Minting Shipping response
Gold Minting
$bodyParameters = [ 'minting_partner' => 'x6A3lOoJXL59zDd', 'minting_fee' => 'JGYPjrXW7XDw2mE', 'minting_piece' => 'KQxz9YXazA14VEO', 'minting_shipping' => '7Jb1VXLrzpm69xv', 'shipping_address' => 'Jalan Prapanca, Jakarta Selatan', 'payment_channel' => 'BRIN', 'latitude' => '-6.914744', 'longitude' => '107.609810', ]; $Tresury = TrsEmas\Minting::goldMinting( true, $bodyParameters, '(Bearer Token)' );
Gold Minting For Partner
$bodyParameters = [ 'minting_partner' => 'x6A3lOoJXL59zDd', 'minting_fee' => 'JGYPjrXW7XDw2mE', 'minting_piece' => 'KQxz9YXazA14VEO', 'minting_shipping' => '7Jb1VXLrzpm69xv', 'shipping_address' => 'Jalan Prapanca, Jakarta Selatan', 'payment_channel' => 'BRIN', 'latitude' => '-6.914744', 'longitude' => '107.609810', ]; $Tresury = TrsEmas\Minting::goldMintingPartner( true, $bodyParameters, '(Bearer Token)' );
User
Get Profile
$Tresury = TrsEmas\User::profile( true, '(Bearer Token)' );
Update Profile
only get Treasury update profile URL
$Tresury = TrsEmas\User::updateProfile( true, '(Bearer Token)' );
Update Password
$bodyParameters = [ 'email' => 'ryuamy.mail@gmail.com', 'password' => '(New Password)', 'password_confirmation' => '(New Password)', 'pin' => '12345', ]; $Tresury = TrsEmas\User::updatePassword( true, $bodyParameters, '(Bearer Token)' );
History
Buy Gold History
$Tresury = TrsEmas\History::buyGoldHistory( true, '(Bearer Token)' );
Sell Gold History
$Tresury = TrsEmas\History::sellGoldHistory( true, '(Bearer Token)' );
Gold Minting History
$Tresury = TrsEmas\History::goldMintingHistory( true, '(Bearer Token)' );
Buy Gold Detail History
$bodyParameters = [ 'invoice_no' => 'TRS42154451', ]; $Tresury = TrsEmas\History::buyGoldDetailHistory( true, $bodyParameters, '(Bearer Token)' );
Sell Gold Detail History
$bodyParameters = [ 'invoice_no' => 'TRS42154451', ]; $Tresury = TrsEmas\History::sellGoldDetailHistory( true, $bodyParameters, '(Bearer Token)' );
Gold Minting Detail History
$bodyParameters = [ 'invoice_no' => 'TRS42154451', ]; $Tresury = TrsEmas\History::goldMintingDetailHistory( true, $bodyParameters, '(Bearer Token)' );
Additional
Check Email Availability
$bodyParameters = [ 'email' => 'ryuamy.mail@gmail.com', ]; $Tresury = TrsEmas\Additional::checkEmailAvailability( true, $bodyParameters );
Security Question
$Tresury = TrsEmas\Additional::securityQuestion( true );
Bank List
$Tresury = TrsEmas\Additional::bankList( true );
Procedure
Registration
- Get Bearer Token from Client Login API
- Get security code list from Security Question API
- Get bank list from Bank List API
- Do customer registration
Gold Transaction
To create gold transaction with treasury payment method, the following procedure is:
- Get gold rate.
- Calculate gold transaction with currency or unit. Gold unit support can be up to 4 digits.
- Get payment method list to take payment_code response.
- Do transactions with endpoints gold buy and sell gold.
To create gold transaction with partner payment method, the following procedure is:
- Get gold rate.
- Calculate gold transaction with currency or unit. Gold unit support can be up to 4 digits
- Do transactions with endpoints gold buy and sell gold.
- Hit endpoint payment notify to ensure payment has been successful.
Minting or Cetak Emas
- Get minting partner list.
- Check minting fee of selected partner.
- Check available minting piece of selected partner.
- Calculate total minting payment.
- Get payment method list to take payment_code response.
- Do transactions.