From 4003c40b232e0a237beef3d4ffe9b76796bbb734 Mon Sep 17 00:00:00 2001 From: Adam Pahlevi Date: Wed, 11 Jan 2017 11:18:22 +0700 Subject: [PATCH] update readme --- README.md | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 63a8077..85f6065 100644 --- a/README.md +++ b/README.md @@ -46,4 +46,38 @@ an advantage of itself. Now, Midtrans is available to be used in Go, too. } resp, _ := coreGateway.Charge(chargeReq) -``` \ No newline at end of file +``` + +### Snap Gateway + +Snap is Midtrans existing tool to help merchant charge customers using a +mobile-friendly, in-page, no-redirect checkout facilities. Using snap is +completely simple. + +```go +var snapGateway midtrans.SnapGateway +snapGateway = midtrans.SnapGateway{ + Client: midclient, +} + +snapResp, err := snapGateway.GetTokenQuick(generateOrderId(), 200000) +var snapToken string +if err != nil { + snapToken = snapResp.Token +} +``` + +On the client side: + +```javascript +var token = $("#snap-token").val(); +snap.pay(token, { + onSuccess: function(res) { alert("Payment accepted!"); }, + onPending: function(res) { alert("Payment pending", res); }, + onError: function(res) { alert("Error", res); } +}); +``` + +You may want to override those `onSuccess`, `onPending` and `onError` +functions to reflect the behaviour that you wished when the charging +result in their respective state.