package
0.5.2
Repository: https://github.com/imrenagi/go-payment.git
Documentation: pkg.go.dev

# README

Example

To start using this module, you can try the example server.go

package main

import (
  "net/http"

  "github.com/gorilla/mux"
  "github.com/imrenagi/go-payment/datastore/inmemory"
  dsmysql "github.com/imrenagi/go-payment/datastore/mysql"
  "github.com/imrenagi/go-payment/gateway/midtrans"
  "github.com/imrenagi/go-payment/invoice"
  "github.com/imrenagi/go-payment/manage"
  "github.com/imrenagi/go-payment/server"
  "github.com/imrenagi/go-payment/util/db/mysql"
  "github.com/imrenagi/go-payment/util/localconfig"
  "github.com/rs/cors"
  "github.com/rs/zerolog/log"
)

func main() {

  secret, err := localconfig.LoadSecret("example/server/secret.yaml")
  if err != nil {
    panic(err)
  }

  db := mysql.NewGorm(secret.DB)
  db.AutoMigrate(
    &midtrans.TransactionStatus{},
    &invoice.Invoice{},
    &invoice.Payment{},
    &invoice.CreditCardDetail{},
    &invoice.LineItem{},
    &invoice.BillingAddress{},
  )

  m := manage.NewManager(secret.Payment)
  m.MustMidtransTransactionStatusRepository(dsmysql.NewMidtransTransactionRepository(db))
  m.MustInvoiceRepository(dsmysql.NewInvoiceRepository(db))
  m.MustPaymentConfigReader(inmemory.NewPaymentConfigRepository("example/server/payment-methods.yml"))

  srv := srv{
    Router:     mux.NewRouter(),
    paymentSrv: server.NewServer(m),
  }
  srv.routes()

  if err := http.ListenAndServe(":8080", srv.GetHandler()); err != nil {
    log.Fatal().Msgf("Server can't run. Got: `%v`", err)
  }

}

To run the application, simply use:

$ go run example/server/server.go

: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 to expose your localhost to the internet and update the callback base URL in payment gateway dashboard and SERVER_BASE_URL accordingly.