paygent

package
v0.0.0-...-2a3cdc3 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2020 License: MIT, MIT Imports: 20 Imported by: 0

README

Paygent

Paygent Golang SDK

Usage

// Initalize
import "github.com/qor/gomerchant/gateways/paygent"
Paygent = paygent.New(&paygent.Config{
  MerchantID:      "PaygentMerchantID",
  ConnectID:       "PaygentConnectID",
  ConnectPassword: "PaygentConnectPassword",
  ClientFilePath:  "PaygentClientFilePath",
  CertPassword:    "CertPassword",
  CAFilePath:      "CAFilePath",
  TelegramVersion: "1.0",
  ProductionMode:  false, // production or sandbox mode
})

// Store Credit Card
Paygent.CreateCreditCard(gomerchant.CreateCreditCardParams{
  CustomerID: "customer_id",
  CreditCard: &gomerchant.CreditCard{
    Name:     "holder name",
    Number:   "3580876521284076",
    ExpMonth: 10,
    ExpYear:  2017,
  },
})

// Get Credit Card
Paygent.GetCreditCard(gomerchant.GetCreditCardParams{CustomerID: "customer_id", CreditCardID: "3580876521284076"})

// Delete Stored Credit Card
Paygent.DeleteCreditCard(gomerchant.DeleteCreditCardParams{CustomerID: "customer_id", CreditCardID: "3580876521284076"})

// List Stored Credit Cards
Paygent.ListCreditCards(gomerchant.ListCreditCardsParams{CustomerID: "customer_id"})

// Take Auth
Paygent.Authorize(100, gomerchant.AuthorizeParams{
  Currency: "JPY",
  OrderID:  "order_id",
  PaymentMethod: &gomerchant.PaymentMethod{
    CreditCard: &gomerchant.CreditCard{
      Name:     "holder name",
      Number:   "3580876521284076",
      ExpMonth: 2,
      ExpYear:  2017,
    },
  },
})

// Take Auth with stored credit card
Paygent.Authorize(100, gomerchant.AuthorizeParams{
  Currency: "JPY",
  OrderID:  "order_id",
  PaymentMethod: &gomerchant.PaymentMethod{
    SavedCreditCard: &gomerchant.SavedCreditCard{
      CustomerID:   "customer id",
      CreditCardID: "stored card id",
    },
  },
})

// Capture
Paygent.Capture("payment_id from paygent", gomerchant.CaptureParams{})

// Refund Auth, 100 is the refuned amount
refundResponse, err := Paygent.Refund("payment id from paygent", 100, gomerchant.RefundParams{})
// after refund, paygent will return a new transaction id, get it from response
refundResponse.TransactionID

// Refund & Capture
refundResponse, err := Paygent.Refund("payment id from paygent", 100, gomerchant.RefundParams{Captured: true})

// Void Auth
Paygent.Void("payment id from paygent", gomerchant.VoidParams{})

// Void Captured Transaction
Paygent.Void("payment id from paygent", gomerchant.VoidParams{Captured: true})

// Query payment
transaction, err := Paygent.Query("payment id from paygent")

type Transaction struct {
	ID        string      // transaction id
	Amount    int         // payment amount
	Currency  string      // currency
	Captured  bool        // authorized and captured
	Paid      bool        // authorized OR captured
	Cancelled bool        // cancelled
	Status    string      // status code from paygent
	CreatedAt *time.Time  // payment created time
	Params                // extra params
}

3D Mode (SecureCode Mode)

authorizeResult, err := Paygent.SecureCodeAuthorize(100,
  paygent.SecureCodeParams{
    UserAgent: "User-Agent	Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12) AppleWebKit/602.3.12 (KHTML, like Gecko) Version/10.0.2 Safari/602.3.12",
    TermURL:    "http://getqor.com/order/return",
    HttpAccept: "http",
  },
  gomerchant.AuthorizeParams{
    OrderID:  "order id",
    PaymentMethod: &gomerchant.PaymentMethod{
      CreditCard: &gomerchant.CreditCard{
        Name:     "holder name",
        Number:   "3580876521284076",
        ExpMonth: 10,
        ExpYear:  2019,
      },
    },
})

// In your controller
if authorizeResult.HandleRequest {
  if err := authorizeResult.RequestHandler(writer, request, gomerchant.Params{}); err == nil {
    return
  }
}

// In return controller (http://getqor.com/order/return)
var params gomerchant.CompleteAuthorizeParams
params.Set("request", request)
Paygent.CompleteAuthorize("payment id from paygent when get auth", params)

Advanced Mode

// Construct API request by yourself
Paygent.Request(telegramKind, gomerchant.Params{})

// For example
paygent.Request("094", gomerchant.Params{"payment_id": "payment id from paygent"})

License

Released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PaygentServerTimeZone, _ = time.LoadLocation("Asia/Tokyo")
View Source
var ResponseParser = regexp.MustCompile(`(?s)(\w+?)=(<!DOCTYPE.*HTML>|.*?)(\r\n|$)`)
View Source
var TelegramServiceDomain = "https://service.paygent.co.jp"
View Source
var TelegramServiceSandboxDomain = "https://sandbox.paygent.co.jp"
View Source
var TelegramServiceURLs = map[string]string{

	"01": "/n/atm/request",

	"02": "/n/card/request",

	"11": "/n/card/request",

	"03": "/n/conveni/request",

	"04": "/n/conveni/request_print",

	"05": "/n/bank/request",

	"06": "/n/bank/requestasp",

	"07": "/n/virtualaccount/request",

	"09": "/n/ref/request",

	"091": "/n/ref/paynotice",

	"093": "/n/ref/runnotice",
	"094": "/n/ref/paymentref",

	"10": "/n/c/request",

	"12": "/n/c/request",

	"20": "/n/o/requestdata",

	"13": "/n/paypal/request",

	"15": "/n/emoney/request",
}

Functions

This section is empty.

Types

type Config

type Config struct {
	MerchantID      string `required:"true"`
	ConnectID       string `required:"true"`
	ConnectPassword string `required:"true"`
	TelegramVersion string

	CertPassword      string
	ClientFilePath    string // this is required, if ClientFileContent is blank
	ClientFileContent string // this is required, if ClientFilePath is blank
	CAFilePath        string // this is required, if CAFileContent is blank
	CAFileContent     string // this is required, if CAFilePath is blank

	ProductionMode bool
}

type Paygent

type Paygent struct {
	Config *Config
}

func New

func New(config *Config) *Paygent

func (*Paygent) Authorize

func (paygent *Paygent) Authorize(amount uint64, params gomerchant.AuthorizeParams) (gomerchant.AuthorizeResponse, error)

func (*Paygent) Capture

func (paygent *Paygent) Capture(transactionID string, params gomerchant.CaptureParams) (gomerchant.CaptureResponse, error)

func (*Paygent) Client

func (paygent *Paygent) Client() (*http.Client, error)

func (*Paygent) CompleteAuthorize

func (paygent *Paygent) CompleteAuthorize(paymentID string, params gomerchant.CompleteAuthorizeParams) (gomerchant.CompleteAuthorizeResponse, error)

func (*Paygent) CreateCreditCard

func (paygent *Paygent) CreateCreditCard(creditCardParams gomerchant.CreateCreditCardParams) (gomerchant.CreditCardResponse, error)

func (*Paygent) DeleteCreditCard

func (paygent *Paygent) DeleteCreditCard(deleteCreditCardParams gomerchant.DeleteCreditCardParams) (gomerchant.DeleteCreditCardResponse, error)

func (*Paygent) GetCreditCard

func (paygent *Paygent) GetCreditCard(getCreditCardParams gomerchant.GetCreditCardParams) (gomerchant.GetCreditCardResponse, error)

func (*Paygent) ListCreditCards

func (paygent *Paygent) ListCreditCards(listCreditCardsParams gomerchant.ListCreditCardsParams) (gomerchant.ListCreditCardsResponse, error)

func (*Paygent) Query

func (paygent *Paygent) Query(transactionID string) (gomerchant.Transaction, error)

func (*Paygent) Refund

func (paygent *Paygent) Refund(transactionID string, amount uint, params gomerchant.RefundParams) (response gomerchant.RefundResponse, err error)

func (*Paygent) Request

func (paygent *Paygent) Request(telegramKind string, params gomerchant.Params) (Response, error)

func (*Paygent) SecureCodeAuthorize

func (paygent *Paygent) SecureCodeAuthorize(amount uint64, secureCodeParams SecureCodeParams, params gomerchant.AuthorizeParams) (gomerchant.AuthorizeResponse, error)

func (*Paygent) Void

func (paygent *Paygent) Void(transactionID string, params gomerchant.VoidParams) (response gomerchant.VoidResponse, err error)

type Response

type Response struct {
	RawBody        string
	Result         string
	ResponseCode   string
	ResponseDetail string
	gomerchant.Params
}

type SecureCodeParams

type SecureCodeParams struct {
	UserAgent  string
	TermURL    string
	HttpAccept string
}

Jump to

Keyboard shortcuts

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