Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rizdaprasetya/midtrans-mobile-merchant-server--php-sample-
Sample for Midtrans mobile backend implementation written in PHP |
https://github.com/rizdaprasetya/midtrans-mobile-merchant-server--php-sample-
api midtrans mobile payment payment-gateway
Last synced: about 1 month ago
JSON representation
Sample for Midtrans mobile backend implementation written in PHP |
- Host: GitHub
- URL: https://github.com/rizdaprasetya/midtrans-mobile-merchant-server--php-sample-
- Owner: rizdaprasetya
- Created: 2016-11-17T05:28:43.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2019-09-25T04:21:41.000Z (over 5 years ago)
- Last Synced: 2024-11-24T05:03:31.368Z (about 1 month ago)
- Topics: api, midtrans, mobile, payment, payment-gateway
- Language: PHP
- Homepage: https://mobile-docs.midtrans.com
- Size: 21.5 KB
- Stars: 18
- Watchers: 3
- Forks: 29
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
Simple Merchant Server Implementation Reference for Mobile SDK (PHP version).
> _Also available in other Language Implementation:_
> * [Ruby Sample Merchant Server for Midtrans Mobile SDK](https://github.com/Midtrans/Merchant-Server-for-Midtrans-Mobile-SDK-Ruby-Sample)
> * [Python Sample Merchant Server for Midtrans Mobile SDK](https://github.com/Midtrans/Merchant-Server-for-Midtrans-Mobile-SDK-Python-Sample)## Description
This is a example mobile SDK server for Midtrans's iOS and Android SDK, as an implementation reference to use the mobile sdk.
Please read more in [Documentation of Midtrans mobile SDK](http://mobile-docs.midtrans.com/).## Purpose
The main idea why this server implementation needed is: **To securely add HTTP Authorization Header** from server side.
This auth header is generated from **server key** (from your Midtrans account), this server key is secret, and should only be kept in server side, not client side (mobile app can be easily reverse engineered to extract any secret).Additionally, it allows you to tweak JSON request parameter as needed from server side.
## Endpoints
There is only one endpoint that are required to use Midtrans mobile SDK:```
POST /charge/
```This endpoint will **proxy (forward)** client request to Midtrans Snap API `'https://app.midtrans.com/snap/v1/transactions'` (or `'https://app.sandbox.midtrans.com/snap/v1/transactions'` for sandbox) with **HTTP Authorization Header** generated based on your Midtrans `Server Key`.
The response of API will be printed/returned to client as is. Example response that will be printed
```
{
"token": "413ae932-471d-4c41-bfb4-e558cc271dcc",
"redirect_url": "https://app.sandbox.midtrans.com/snap/v2/vtweb/413ae932-471d-4c41-bfb4-e558cc271dcc"
}
```## Usage
Edit file `charge/index.php`, insert your Midtrans Account Server Key to `''`.
Upload these to your host, and make sure the url `/charge/index.php` can be accessed from the mobile app.Set `/charge/index.php` as `merchant base url` in mobile SDK. (refer to [Midtrans mobile SDK doc](https://mobile-docs.midtrans.com))
> **Advanced Tips:**
> You can also configure your HTTP server to route `/charge/` url to `/charge/index.php` file.
> So the `merchant base url` can be just configured as `/`(without charge/index.php, because SDK will automatically convert it to `/charge/` then your server will route to `/charge/index.php/`).## Testing
You can mock client's request by executing this CURL command to the `/charge/index.php` endpoint:```
curl -X POST -d '{
"transaction_details":{
"order_id":"mobile-12345",
"gross_amount":280000
},
"item_details":[
{
"id":"A01",
"price":280000,
"quantity":1,
"name":"Mie Ayam Komplit"
}
],
"customer_details":[
{
"email":"[email protected]",
"first_name":"Budi",
"last_name":"Khannedy",
"phone":"628112341234"
}
]
}' "https:///charge/index.php/"
```Note: dont forget to change `"http:///charge/index.php/"` to your url where you hosted the `/charge/index.php`.
You can also import that curl command to Postman.
## Notes
This is just for very basic implementation reference, in production, you should implement your backend more securely.## Troubleshooting
When request sent to the url `https:///charge/index.php` fail, try to change the url to `https:///charge/`### Get help
* [Midtrans ](https://www.midtrans.com)
* [Midtrans registration](https://dashboard.midtrans.com/register)
* [Midtrans documentation](http://docs.midtrans.com)
* Can't find answer you looking for? email to [[email protected]](mailto:[email protected])