/go-gmo-pg

Unofficial golang library for GMO Payment Gateway

Primary LanguageGo

go-gmo-pg

GoDoc Release Build Status Codecov Coverage Go Report Card Downloads

Unofficial golang library for GMO Payment Gateway.

Current Supported Payment API List

  • au
    • AuAcceptUserEnd.idPass
    • AuContinuanceCancel.idPass
    • AuContinuanceChargeCancel.idPass
    • EntryTranAuAccept.idPass
    • EntryTranAuContinuance.idPass
    • EntryTranAu.idPass
    • ExecTranAuAccept.idPass
    • ExecTranAuContinuance.idPass
    • ExecTranAu.idPass

Quick Usage

EntryTranAuAccept and ExecTranAuAccept

import (
	"fmt"
	"os"

	"github.com/evalphobia/go-gmo-pg/config"
	"github.com/evalphobia/go-gmo-pg/client"
	"github.com/evalphobia/go-gmo-pg/client/au"
)

func getClient() client.Client {
	shopID := os.Getenv("GMO_PG_SHOP_ID")
	shopPass := os.Getenv("GMO_PG_SHOP_PASS")
	isProdMode := os.Getenv("GMO_PG_PRODUCTION_MODE") != ""
	useDebugOption := os.Getenv("GMO_PG_DEBUG_OPTION") != ""

	conf, err := config.New(shopID, shopPass)
	if err != nil {
		panic(err)
	}

	if isProdMode {
		conf.SetAsProduction()
	}

	cli := client.New(conf)
	cli.Option.Retry = true
	cli.Option.Debug = useDebugOption
	return cli
}

func main() {
	cli := getClient()

	entryAPI := au.EntryTranAu{
		OrderID:     "001_abcdefg",
	}
	entryResp, err := entryAPI.Do(cli)
	switch {
	case err != nil:
		panic(err)
	case !entryResp.IsSuccess():
		// error process...
		return
	}

	execAPI := au.ExecTranAuAccept{
		OrderID:        entryAPI.OrderID,
		AccessID:       entryResp.AccessID,
		AccessPass:     entryResp.AccessPass,
		Commodity:      "the product name",
		ServiceName:    "my service name",
		ServiceTel:     "+81-3-0000-0000",
		RetURL:         "https://example.com/return",
		PaymentTermSec: 300, // 5min
	}
	execResp, err := execAPI.DoWithSjis(cli)
	switch {
	case err != nil:
		panic(err)
	case !execResp.IsSuccess():
		// error process...
		return
	}

	respData := map[string]string{
		"redirect_url": execResp.StartURL,
		"order_id":     entryAPI.OrderID,
		"access_id":    execResp.AccessID,
		"token":        execResp.Token,
	}
	fmt.Printf("%+v", respData)
}

EntryTranAu and ExecTranAu

import (
	"fmt"
	"os"

	"github.com/evalphobia/go-gmo-pg/config"
	"github.com/evalphobia/go-gmo-pg/client"
	"github.com/evalphobia/go-gmo-pg/client/au"
)

func getClient() client.Client {
	shopID := os.Getenv("GMO_PG_SHOP_ID")
	shopPass := os.Getenv("GMO_PG_SHOP_PASS")
	isProdMode := os.Getenv("GMO_PG_PRODUCTION_MODE") != ""
	useDebugOption := os.Getenv("GMO_PG_DEBUG_OPTION") != ""

	conf, err := config.New(shopID, shopPass)
	if err != nil {
		panic(err)
	}

	if isProdMode {
		conf.SetAsProduction()
	}

	cli := client.New(conf)
	cli.Option.Retry = true
	cli.Option.Debug = useDebugOption
	return cli
}

func main() {
	cli := getClient()

	entryAPI := au.EntryTranAu{
		OrderID:     "001_abcdefg",
		Amount:      1200,
		JobCd:       client.StatusCapture,
		PaymentType: client.AuPaymentTypeAcceptCode,
	}
	entryResp, err := entryAPI.Do(cli)
	switch {
	case err != nil:
		panic(err)
	case !entryResp.IsSuccess():
		// error process...
		return
	}

	execAPI := au.ExecTranAu{
		OrderID:      entryAPI.OrderID,
		AccessID:     entryResp.AccessID,
		AccessPass:   entryResp.AccessPass,
		Commodity:    "the product name",
		ServiceName:  "my service name",
		ServiceTel:   "+81-3-0000-0000",
		AuAcceptCode: "T1000000000000",
		ClientField1: "debug code 1",
	}
	execResp, err := execAPI.DoWithSjis(cli)
	switch {
	case err != nil:
		panic(err)
	case execResp.HasErrorAuAcceptCodeNotFound(),
		!execResp.IsSuccess():
		// error process...
		return
	}

	fmt.Printf("success payment: %+v", execResp)
}