server

command
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2020 License: MIT Imports: 13 Imported by: 0

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

❗ 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.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL