Skip to content

Commit a26e250

Browse files
committed
Update readme
Signed-off-by: Imre Nagi <[email protected]>
1 parent a9081ea commit a26e250

File tree

9 files changed

+545
-334
lines changed

9 files changed

+545
-334
lines changed

README.md

Lines changed: 6 additions & 198 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,6 @@ Payment module used as proxy for multiple payment gateways. Currently it only su
3535
- [Mandatory Environment Variables](#mandatory-environment-variables)
3636
- [Example Code](#example-code)
3737
- [API Usage](#api-usage)
38-
- [POSTMAN JSON](#postman-json)
39-
- [List of payment methods](#list-of-payment-methods)
40-
- [Request](#request)
41-
- [Response](#response)
42-
- [Generating New Invoice](#generating-new-invoice)
43-
- [Request](#request-1)
44-
- [Response](#response-1)
45-
- [For Midtrans Payment Channel](#for-midtrans-payment-channel)
46-
- [For Xendit Payment Channel](#for-xendit-payment-channel)
4738
- [Contributing](#contributing)
4839
- [License](#license)
4940

@@ -55,13 +46,14 @@ Payment module used as proxy for multiple payment gateways. Currently it only su
5546

5647
In general, this payment proxy can support payment through this following channels:
5748

49+
- Recurring payment with Credit Card, OVO, Bank Transfer
5850
- Credit card payment with/without installment
5951
- Ewallet (GoPay, OVO, Dana, LinkAja)
6052
- Retail Outlet (Alfamart, Alfamidi, Dan+Dan)
6153
- Cardless Credit (Akulaku)
62-
- Bank Transfer via Virtual Account (BCA, BNI, Mandiri, Permata, Other Bank). BRI channel is coming.
54+
- Bank Transfer via Virtual Account (BCA, BNI, BRI, Mandiri, Permata, Other Bank).
6355

64-
> :heavy_exclamation_mark: Support for recurring payment will be added soon!
56+
> :heavy_exclamation_mark: Recurring payment is only supported via XenditInvoice.
6557
6658
## Why you should use this payment proxy?
6759

@@ -98,7 +90,7 @@ This tables shows which payment channels that has been implemented by this proxy
9890
| Other VA | :white_check_mark: | :x: |
9991
| BRI VA | :x: | :white_check_mark: |
10092
| Alfamart, Alfamidi, Dan+Dan | :white_check_mark: | :white_check_mark: |
101-
| QRIS | :white_check_mark: via Gopay Option | :x: |
93+
| QRIS | :white_check_mark: | n/a |
10294
| Gopay | :white_check_mark: | :x: |
10395
| OVO | :x: | :white_check_mark: |
10496
| DANA | :x: | :white_check_mark: |
@@ -303,195 +295,11 @@ export FAILED_REDIRECT_PATH="/donate/error"
303295

304296
## Example Code
305297

306-
To start using this module, you can try the example [server.go](/example/server/server.go)
307-
308-
```go
309-
package main
310-
311-
import (
312-
"net/http"
313-
314-
"github.com/gorilla/mux"
315-
"github.com/imrenagi/go-payment/datastore/inmemory"
316-
dsmysql "github.com/imrenagi/go-payment/datastore/mysql"
317-
"github.com/imrenagi/go-payment/gateway/midtrans"
318-
"github.com/imrenagi/go-payment/invoice"
319-
"github.com/imrenagi/go-payment/manage"
320-
"github.com/imrenagi/go-payment/server"
321-
"github.com/imrenagi/go-payment/util/db/mysql"
322-
"github.com/imrenagi/go-payment/util/localconfig"
323-
"github.com/rs/cors"
324-
"github.com/rs/zerolog/log"
325-
)
326-
327-
func main() {
328-
329-
secret, err := localconfig.LoadSecret("example/server/secret.yaml")
330-
if err != nil {
331-
panic(err)
332-
}
333-
334-
db := mysql.NewGorm(secret.DB)
335-
db.AutoMigrate(
336-
&midtrans.TransactionStatus{},
337-
&invoice.Invoice{},
338-
&invoice.Payment{},
339-
&invoice.CreditCardDetail{},
340-
&invoice.LineItem{},
341-
&invoice.BillingAddress{},
342-
)
343-
344-
m := manage.NewManager(secret.Payment)
345-
m.MustMidtransTransactionStatusRepository(dsmysql.NewMidtransTransactionRepository(db))
346-
m.MustInvoiceRepository(dsmysql.NewInvoiceRepository(db))
347-
m.MustPaymentConfigReader(inmemory.NewPaymentConfigRepository("example/server/payment-methods.yml"))
348-
349-
srv := srv{
350-
Router: mux.NewRouter(),
351-
paymentSrv: server.NewServer(m),
352-
}
353-
srv.routes()
354-
355-
if err := http.ListenAndServe(":8080", srv.GetHandler()); err != nil {
356-
log.Fatal().Msgf("Server can't run. Got: `%v`", err)
357-
}
358-
359-
}
360-
```
361-
362-
To run the application, simply use:
363-
364-
```console
365-
$ go run example/server/server.go
366-
```
367-
368-
> :heavy_exclamation_mark: If you want to accept payment callback from the payment gateway on your local computer for development purpose, consider to use [ngrok.io](https://ngrok.io) to expose your localhost to the internet and update the callback base URL in payment gateway dashboard and `SERVER_BASE_URL` accordingly.
298+
You can find the sample code in [here](/example/server)
369299

370300
## API Usage
371301

372-
Your client webservice can interact to at least 2 endpoints:
373-
374-
- GET all payment methods available
375-
- POST generating new invoice
376-
377-
### POSTMAN JSON
378-
379-
You can download this POSTMAN json file to see how to use the api. [POSTMAN COLLECTION](/example/server/go-payment.postman_collection.json)
380-
381-
### List of payment methods
382-
383-
#### Request
384-
385-
If you want to get the estimated admin/installment fee for each payment methods, provice this GET request with optional `price` and `currency` query. Otherwise, it returns nil `admin_fee` and `installment_fee`
386-
387-
```http
388-
GET /payment/methods?price=1000&currency=IDR
389-
```
390-
391-
#### Response
392-
393-
```json
394-
{
395-
"card_payment": {
396-
"payment_type": "credit_card",
397-
"installments": [
398-
{
399-
"display_name": "",
400-
"type": "offline",
401-
"bank": "bca",
402-
"terms": [
403-
{
404-
"term": 0,
405-
"admin_fee": {
406-
"value": 2029,
407-
"curency": "IDR"
408-
}
409-
}
410-
]
411-
}
412-
]
413-
},
414-
// ... redacted ...
415-
"ewallets": [
416-
{
417-
"payment_type": "gopay",
418-
"display_name": "Gopay",
419-
"admin_fee": {
420-
"value": 0,
421-
"curency": "IDR"
422-
}
423-
}
424-
]
425-
}
426-
```
427-
428-
### Generating New Invoice
429-
430-
Use this endpoint to create a payment request to chosen payment channels and gateway.
431-
432-
#### Request
433-
434-
```http
435-
POST /payment/invoices
436-
```
437-
438-
```json
439-
{
440-
"payment": {
441-
"payment_type": "ovo"
442-
},
443-
"customer": {
444-
"name": "John",
445-
"email": "[email protected]",
446-
"phone_number": "089922222222"
447-
},
448-
"items": [{
449-
"name": "Support Podcast",
450-
"category": "PODCAST",
451-
"merchant": "imrenagi.com",
452-
"description": "donasi podcast imre nagi",
453-
"qty": 1,
454-
"price": 80001,
455-
"currency": "IDR"
456-
}]
457-
}
458-
```
459-
460-
> To create invoice with `credit_card` payment with/without installment, please take a look [POSTMAN COLLECTION](/example/server/go-payment.postman_collection.json)
461-
462-
#### Response
463-
464-
When you call endpoint above, server returns all invoice data. But, to proceed to the payment page you need to pay attention to `payment` object.
465-
466-
```json
467-
{
468-
"payment": {
469-
"id": 48,
470-
"created_at": "2020-05-25T23:31:44.99873+07:00",
471-
"updated_at": "2020-05-25T23:31:44.99873+07:00",
472-
"deleted_at": null,
473-
"gateway": "xendit",
474-
"payment_type": "ovo",
475-
"token": "",
476-
"redirect_url": "https://invoice.xendit.co/web/invoices5ecbf2f0689543409347ec15",
477-
"transaction_id": "5ecbf2f0689543409347ec15"
478-
}
479-
}
480-
```
481-
482-
:heavy_exclamation_mark::heavy_exclamation_mark::heavy_exclamation_mark: Please note:
483-
484-
#### For Midtrans Payment Channel
485-
486-
- Value of `payment.gateway` will is always `midtrans`
487-
- You can use `payment.token` to open snap window by using midtrans [snap.js](https://snap-docs.midtrans.com/#snap-js)
488-
- If you want to use [Window Redirection](https://snap-docs.midtrans.com/#window-redirection), you can open a new browser tab by using url in `payment.redirect_url`
489-
490-
#### For Xendit Payment Channel
491-
492-
- Value of `payment.gateway` will is always `xendit`
493-
- `payment.token` is always empty for all xendit provided payment channels
494-
- You will always open `payment.redirect_url` in new browser tap for all payment methods provided by xendit. Including DANA, LinkAja, Kredivo, even Xendit Invoice.
302+
You can find the details of API usage in [here](/docs)
495303

496304
## Contributing
497305

docs/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
How to Use API
2+
===
3+
4+
## Table of Contents:
5+
6+
- [Postman Collections](./go-payment.postman_collection.json)
7+
- [Payment Methods](./methods.md)
8+
- [Invoices](./invoice.md)
9+
- [Subscription](./subscription.md)
10+

0 commit comments

Comments
 (0)