Home

Awesome

<!-- markdownlint-disable MD014 MD024 MD026 MD033 MD036 MD041 --> <div align='center'>

go-payment

</div>

Payment module used as proxy for multiple payment gateways. Currently it only supports Midtrans SNAP and Xendit Ewallet and XenInvoice. Support for other channels will be added incrementally.

This payment proxy is a payment service I used for my personal site. Thinking that this might be useful to help other people so that they can start accept money ASAP, so I decided to make this module open source.


<details> <summary><b>View table of contents</b></summary><br/> </details>

Payment Channels Supported

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

:heavy_exclamation_mark: Recurring payment is only supported via XenditInvoice.

Why you should use this payment proxy?

Current Limitations

  1. For simplify the query creation for database join, I use gorm.io as the ORM library.
  2. This proxy is not made for supporting all use cases available out there. It's hard requirement is just so that people can accept payment with as low effort as possible without need to worry about custom UI flow.
  3. No callback trigger at least of now once the payment manager is done procesing this request. This will be the next priority of the next release. This issue is documented here
  4. Callback or redirect URL is globally configured. This means, you cant configure callback for each request differently on the fly.

Implemented Channels

This tables shows which payment channels that has been implemented by this proxy.

:white_check_mark: : ready

:heavy_exclamation_mark: : in progress

:x: : not yet supported natively by payment gateway

ChannelsMidtrans (Snap)Xendit (ewallet/XenInvoice)
Credit Card without installment:white_check_mark::white_check_mark:
Credit Card with installment:white_check_mark::x:
BCA VA:white_check_mark::white_check_mark:
Mandiri VA:white_check_mark::white_check_mark:
BNI VA:white_check_mark::white_check_mark:
Permata VA:white_check_mark::white_check_mark:
Other VA:white_check_mark::x:
BRI VA:heavy_exclamation_mark::white_check_mark:
Alfamart, Alfamidi, Dan+Dan:white_check_mark::white_check_mark:
QRIS:white_check_mark::white_check_mark:
Gopay:white_check_mark::x:
OVO:x::white_check_mark:
DANA:x::white_check_mark:
LinkAja:x::white_check_mark:
ShopeePay:white_check_mark::white_check_mark:
Akulaku:white_check_mark::x:
Kredivo:x::heavy_exclamation_mark:

Getting Started

Here some preparations that you might need before using this proxy.

Payment Gateway Registration

This can be tricky. If you have personal business, this might be easier. If you have business entity (PT, CV, etc), there are some additional processes you have to follow and some documents that you have to provide. In this context, I will just assume that you have personal business like what I do: imrenagi.com

Midtrans

Please review this page before creating an account.

Xendit

Please visit this registration page for creating an account.

Midtrans VS Xendit Onboarding

Here is the comparison between Midtrans and Xendit onboarding based on my onboarding experience.

CriteriaMidtransXendit
Document to provide for registrationKTP, NPWPKTP, NPWP
Cooperation Agreement (Perjanjian Kerja Sama)Online SigningPaper Signing and use Legalized Stamp
Active channels after agreement is signedGopay, Bank TransferBank Transfer, Credit Card
OVO, LinkAja, Dana activationn/aFill additional forms on the dashboard. Activation varies between weeks - months
Alfamart activationRequire additional request and midtrans review for the activationNo need to be PT, CV. Just fill and sign additional form on the dashboard. Might take weeks or months.
Credit card activationRequire additional request and midtrans review for the activationImmediately activated after document sign
Disbursement featureNot included on the same PKS. Need to contact IRIS team for new agreement, activation and onboardingImmediately activated after document sign
Akulaku activationMight require business entity (PT, CV)n/a
Kredivo activationn/aAsk your account manager to activate this payment method
API DocumentationAvailableAvailable
Golang SDKAvailableAvailable, but under development. Expect breaking changes in newer version

Payment Gateway Callback

Since this library is just providing the http.Handler, you can choose the REST API endpoint used by each callback. You can check the example on server.go.

Some Xendit Legacy Ewallet API(s) require you to set callback and redirect URL on the body request. You can override this value by using environment variables. Go to Mandatory Environment Variables.

Midtrans

To set your callback URL,

Xendit

To set your callback URL,

LinkAja and DANA callback URL are not defined on xendit dashboard. Instead, they are given while the proxy is initiating the payment request to Xendit API. You can find the callback URL set on linkaja.go and dana.go

Application Secret

Before using this application, you might need to update secret.yaml file containing application secret like database and payment gateway credential.

Application Config

As of now, application config stores configuration about which API that you would like to use for Xendit ewallet payments such as Dana, OVO, and LinkAja. Please check config.yaml.

xendit:
  ewallet:
    ovo:
      invoice: false
      legacy: false

Database

I removed MySQL as default database for this library. This library only accept instance of gorm.DB for database. Thus, you can use any database you like and provide the gorm.DB instance of chosen database.

For more, please check server.go

Midtrans Credential

payment:
  midtrans:
    secretKey: "midtrans-server-secret"
    clientKey: "midtrans-client-key"
    clientId: "midtrans-merchant-id"

Xendit Credential

payment:
  ...
  xendit:
    secretKey: "xendit-api-key"
    callbackToken: "xendit-callback-token"

Configuration File

You can take a look sample configuration file named payment-methods.yml. For instance:

card_payment:
  payment_type: "credit_card"
  installments:
    - type: offline
      display_name: ""
      gateway: midtrans
      bank: bca
      channel: migs
      default: true
      active: true
      terms:
        - term: 0
          admin_fee:
            IDR:
              val_percentage: 2.9
              val_currency: 2000
              currency: "IDR"
        - term: 3
          installment_fee:
            IDR:
              val_percentage: 5.5
              val_currency: 2200
              currency: "IDR"

With above configuration, for installment offline with bca, you can apply this following fees to the invoice after user generates new invoice:

  1. 2.9% + IDR 2000 admin fee for credit card transaction without any installment, or
  2. 5.5% + IDR 2200 installment fee for credit card transaction with installment for 3 month tenure.

If you want to absorb the fee, you can simply set val_percentage and val_currency as 0

If you only want to apply fee just either by using val_pecentage or val_currency, simply set the value to one of them and give 0 to the other. For instance:

bank_transfers:
  - gateway: midtrans
    payment_type: "bca_va"
    display_name: "BCA"
    admin_fee:
      IDR:
        val_percentage: 0
        val_currency: 4000
        currency: "IDR"

admin_fee and installment_fee are optional key.

Mandatory Environment Variables

You need to set these environment variables to make sure this proxy to work.

Environment VariableRequiredDescriptionExample
ENVIRONMENTyesdecide whether the server is for testing or production. For production, use prod.prod
LOG_LEVELnoLog level. Default to DEBUG. Available values: DEBUG, INFO, WARN, ERRORDEBUG
INVOICE_SUCCESS_REDIRECT_URLyesRedirect URL used by xendit if invoice is successfully paidhttp://example.com/donate/thanks
INVOICE_FAILED_REDIRECT_URLyesRedirect URL used by xendit if invoice is failedhttp://example.com/donate/error
DANA_LEGACY_CALLBACK_URLyes, if you are using legacy ewallet xendit APICallback URL used for xendit legacy ewallet API to send payment callbackhttp://api.example.com/payment/xendit/dana/callback
DANA_LEGACY_REDIRECT_URLyes, if you are using legacy ewallet xendit APIRedirect URL used by xendit legacy ewallet API to redirect user after payment succeededhttp://example.com/donate/thanks
LINKAJA_LEGACY_CALLBACK_URLyes, if you are using legacy ewallet xendit APICallback URL used for xendit legacy ewallet API to send payment callbackhttp://api.example.com/payment/xendit/linkaja/callback
LINKAJA_LEGACY_REDIRECT_URLyes, if you are using legacy ewallet xendit APIRedirect URL used by xendit legacy ewallet API to redirect user after payment succeededhttp://example.com/donate/thanks
RECURRING_SUCCESS_REDIRECT_URLyes, if you are using subscription featureRedirect URL used by xendit subscription API to redirect user after payment succeededhttp://example.com/donate/thanks
RECURRING_FAILED_REDIRECT_URLyes, if you are using subscription featureRedirect URL used by xendit subscription API to redirect user after payment failedhttp://example.com/donate/error
DANA_SUCCESS_REDIRECT_URLyes, if you are using new xendit ewallet APIRedirect URL used by xendit new ewallet API if payment with dana is successhttp://example.com/success
LINKAJA_SUCCESS_REDIRECT_URLyes, if you are using new xendit ewallet APIRedirect URL used by xendit new ewallet API if payment with dana is failedhttp://example.com/success

Example Code

You can find the sample code in here

API Usage

You can find the details of API usage in here

Contributing

No rules for now. Feel free to add issue first and optionally submit a PR. Cheers

License

MIT. Copyright 2022 Imre Nagi