Cara menggunakan is php becoming obsolete?
This is the Official PHP wrapper/library for Midtrans Payment API, that is compatible with Composer. Visit https://midtrans.com for more information about the product and see documentation at http://docs.midtrans.com for more technical details. Show
1. Installation1.a Composer InstallationIf you are using Composer, you can install via composer CLI:
or add this require line to your require_once dirname(__FILE__) . '/pathofproject/Midtrans.php'; // my code goes here3 file: { "require": { "midtrans/midtrans-php": "2.*" } } and run require_once dirname(__FILE__) . '/pathofproject/Midtrans.php'; // my code goes here4 on your terminal.
require_once dirname(__FILE__) . '/pathofproject/Midtrans.php'; // my code goes here6 will then be available (auto loaded) as Object in your Laravel project. 1.b Manual InstalationIf you are not using Composer, you can clone or download this repository. Then you should require/autoload require_once dirname(__FILE__) . '/pathofproject/Midtrans.php'; // my code goes here7 file on your code. require_once dirname(__FILE__) . '/pathofproject/Midtrans.php'; // my code goes here 2. How to Use2.1 General Settings// Set your Merchant Server Key \Midtrans\Config::$serverKey = ' Override Notification URLYou can opt to change or add custom notification urls on every transaction. It can be achieved by adding additional HTTP headers into charge request. // Add new notification url(s) alongside the settings on Midtrans Dashboard Portal (MAP) Config::$appendNotifUrl = "https://example.com/test1,https://example.com/test2"; // Use new notification url(s) disregarding the settings on Midtrans Dashboard Portal (MAP) Config::$overrideNotifUrl = "https://example.com/test1";
Idempotency-KeyYou can opt to add idempotency key on charge transaction. It can be achieved by adding additional HTTP headers into charge request. Is a unique value that is put on header on API request. Midtrans API accept Idempotency-Key on header to safely handle retry request without performing the same operation twice. This is helpful for cases where merchant didn't receive the response because of network issue or other unexpected error. Config::$paymentIdempotencyKey = "Unique-ID"; 2.2 Choose Product/MethodWe have 3 different products of payment that you can use:
Choose one that you think best for your unique needs. 2.2.a SnapYou can see Snap example here. Get Snap Token$params = array( 'transaction_details' => array( 'order_id' => rand(), 'gross_amount' => 10000, ) ); $snapToken = \Midtrans\Snap::getSnapToken($params); Initialize Snap JS when customer click pay button<html> <body> <button id="pay-button">Pay!button> <pre><div id="result-json">JSON result will appear here after payment:<br>div>pre> <script src="https://app.sandbox.midtrans.com/snap/snap.js" data-client-key=" Implement Notification Handler2.2.b Snap RedirectYou can see some Snap Redirect examples here. Get Redirection URL of a Payment Page$params = array( 'transaction_details' => array( 'order_id' => rand(), 'gross_amount' => 10000, ) ); try { // Get Snap Payment Page URL $paymentUrl = \Midtrans\Snap::createTransaction($params)->redirect_url; // Redirect to Snap Payment Page header('Location: ' . $paymentUrl); } catch (Exception $e) { echo $e->getMessage(); } Implement Notification Handler2.2.c Core API (VT-Direct)You can see some Core API examples here. Set Client KeyMidtransNew3ds.clientKey = " Checkout PagePlease refer to this file Checkout Process1. Create Transaction Details{ "require": { "midtrans/midtrans-php": "2.*" } }0 2. Create Item Details, Billing Address, Shipping Address, and Customer Details (Optional){ "require": { "midtrans/midtrans-php": "2.*" } }1 3. Get Token ID from Checkout Page{ "require": { "midtrans/midtrans-php": "2.*" } }2 4. Create Transaction Data{ "require": { "midtrans/midtrans-php": "2.*" } }3 5. Charge{ "require": { "midtrans/midtrans-php": "2.*" } }4 6. Credit Card 3DS AuthenticationThe credit card charge result may contains // Set your Merchant Server Key \Midtrans\Config::$serverKey = '1 for 3DS authentication. 3DS Authentication should be handled on Frontend please refer to For full example on Credit Card 3DS transaction refer to:
7. Handle Transaction Status{ "require": { "midtrans/midtrans-php": "2.*" } }5 8. Implement Notification Handler2.3 Handle HTTP NotificationCreate separated web endpoint (notification url) to receive HTTP POST notification callback/webhook. HTTP notification will be sent whenever transaction status is changed. Example also available here { "require": { "midtrans/midtrans-php": "2.*" } }6 2.4 Process TransactionGet Transaction Status{ "require": { "midtrans/midtrans-php": "2.*" } }7 Approve TransactionIf transaction fraud_status == CHALLENGE, you can approve the transaction from Merchant Dashboard, or API : { "require": { "midtrans/midtrans-php": "2.*" } }8 Cancel TransactionYou can Cancel transaction with // Set your Merchant Server Key \Midtrans\Config::$serverKey = '2, or credit card transaction with // Set your Merchant Server Key \Midtrans\Config::$serverKey = '3 (before it become SETTLEMENT) { "require": { "midtrans/midtrans-php": "2.*" } }9 Expire TransactionYou can Expire transaction with // Set your Merchant Server Key \Midtrans\Config::$serverKey = '4 (before it become SETTLEMENT or EXPIRE) { "require": { "midtrans/midtrans-php": "2.*" } }9 Refund TransactionRefund a transaction (not all payment channel allow refund via API) You can Refund transaction with // Set your Merchant Server Key \Midtrans\Config::$serverKey = '5 require_once dirname(__FILE__) . '/pathofproject/Midtrans.php'; // my code goes here1 Direct Refund TransactionRefund a transaction via Direct Refund API You can Refund transaction with // Set your Merchant Server Key \Midtrans\Config::$serverKey = '5 require_once dirname(__FILE__) . '/pathofproject/Midtrans.php'; // my code goes here2 Unit TestIntegration Test (sandbox real transactions)Please change server key and client key on // Set your Merchant Server Key \Midtrans\Config::$serverKey = '7 to your own. All Test// Set your Merchant Server Key \Midtrans\Config::$serverKey = '8 Specific Test// Set your Merchant Server Key \Midtrans\Config::$serverKey = '9 ContributingDeveloping e-commerce plug-insThere are several guides that must be taken care of when you develop new plugins.
|