Coder Social home page Coder Social logo

go-gmo-pg's Introduction

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)
}

go-gmo-pg's People

Contributors

evalphobia avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.