linepay

package module
v0.0.0-...-f69af37 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

README

GitHub license GoDoc

line-pay-sdk-go

LINE Pay API SDK for Go LINE Pay Developers Website

Supported LINE Pay v3 APIs


  • Request API
  • Confirm API
  • Capture API (not test yet)
  • Void API
  • Refund API
  • Payment Details API
  • Check Payment Status API
  • Check RegKey API
  • Pay Preapproved API
  • Expire RegKey API

Usage

go get -v github.com/chy168/line-pay-sdk-go

How to test

develop

replace necessary information in data_test.go, then you can go test what you want to try.

test

there is a built in web server to perform confirm api by transaction (can be used as confirmURL)

go run examples/cmd/callback_server.go --channel-id=<YOUR_CHANNEL_ID> --channel-secret=<YOUR_CHANNEL_SECRET>

LICENSE

Apache 2.0

Documentation

Index

Constants

View Source
const (
	APIHostSandbox    = "https://sandbox-api-pay.line.me"
	APIHostProduction = "https://api-pay.line.me"
)
View Source
const (
	PaymentsDetailsFieldsTransaction string = "RANSACTION"
	PaymentsDetailsFieldsOrder       string = "ORDER"
	PaymentsDetailsFieldsDefault     string = "ALL"
)
View Source
const (
	PaymentsConfirmUrlTypeClient string = "CLIENT"
	PaymentsConfirmUrlTypeServer string = "SERVER"
	PaymentsConfirmUrlTypeNone   string = "NONE"
)
View Source
const (
	ApiReturnCodeSuccess string = "0000"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(channelID, channelSecret string, signer *Signer, opts *ClientOpts) (*Client, error)

func (*Client) PaymentsCapture

func (client *Client) PaymentsCapture(ctx context.Context, transactionId int64, request *PaymentsCaptureRequest) (response *PaymentsCaptureResponse, err error)

PaymentsCapture Transactions that have set options.payment.capture as false when requesting the Request API payment will be put on hold when the payment is completed with the Confirm API. In order to finalize the payment, an additional purchase with Capture API is required.

func (*Client) PaymentsConfirm

func (client *Client) PaymentsConfirm(ctx context.Context, transactionId int64, request *PaymentsConfirmRequest) (response *PaymentsConfirmResponse, err error)

func (*Client) PaymentsDetails

func (client *Client) PaymentsDetails(ctx context.Context, request *PaymentsDetailsRequest) (response *PaymentsDetailsResponse, err error)

PaymentsDetails

func (*Client) PaymentsRequest

func (client *Client) PaymentsRequest(ctx context.Context, request *PaymentsRequest) (response *PaymentsResponse, err error)

type ClientOpts

type ClientOpts struct {
	ProductionEnabled bool
}

type PaymentsCaptureRequest

type PaymentsCaptureRequest struct {
	Amount   int    `json:"amount"`
	Currency string `json:"currency"` // USD, JPY, TWD, THB
}

PaymentsCaptureRequest request body of capture api

type PaymentsCaptureResponse

type PaymentsCaptureResponse struct {
	ReturnCode    string `json:"returnCode"`
	ReturnMessage string `json:"returnMessage"`
	Info          struct {
		TransactionID int64  `json:"transactionId"`
		OrderID       string `json:"orderId"`
		PayInfo       []struct {
			Method string `json:"method"`
			Amount int    `json:"amount"`
		} `json:"payInfo"`
	} `json:"info"`
}

PaymentsCaptureResponse response body of capture api `info[].payInfo[].method`: CREDIT_CARD, BALANCE, DISCOUNT

type PaymentsConfirmInfoPackagesResponse

type PaymentsConfirmInfoPackagesResponse struct {
	ID            string `json:"id"`
	Amount        int    `json:"amount"`
	UserFeeAmount int    `json:"userFeeAmount"`
}

type PaymentsConfirmInfoPayInfoResponse

type PaymentsConfirmInfoPayInfoResponse struct {
	Method                 string `json:"method"`
	Amount                 int    `json:"amount"`
	CreditCardNickname     string `json:"creditCardNickname"`
	CreditCardBrand        string `json:"creditCardBrand"`        // VISA, MASTER, AMEX, DINERS, JCB
	MaskedCreditCardNumber string `json:"maskedCreditCardNumber"` // Format: **** **** **** 1234
}

type PaymentsConfirmInfoResponse

type PaymentsConfirmInfoResponse struct {
	OrderID                 string                                `json:"orderId"`
	TransactionID           int64                                 `json:"transactionId"`
	AuthorizationExpireDate time.Time                             `json:"authorizationExpireDate"`
	RegKey                  string                                `json:"regKey"`
	PayInfo                 []PaymentsConfirmInfoPayInfoResponse  `json:"payInfo"`
	Packages                []PaymentsConfirmInfoPackagesResponse `json:"packages"`
	Shipping                PaymentsConfirmInfoShippingResponse   `json:"shipping"`
}

type PaymentsConfirmInfoShippingAddressRecipientResponse

type PaymentsConfirmInfoShippingAddressRecipientResponse struct {
	FirstName         string `json:"firstName"`
	LastName          string `json:"lastName"`
	FirstNameOptional string `json:"firstNameOptional"`
	LastNameOptional  string `json:"lastNameOptional"`
	Email             string `json:"email"`
	PhoneNo           string `json:"phoneNo"`
}

type PaymentsConfirmInfoShippingAddressResponse

type PaymentsConfirmInfoShippingAddressResponse struct {
	Country    string                                              `json:"country,omitempty"`
	PostalCode string                                              `json:"postalCode,omitempty"`
	State      string                                              `json:"state,omitempty"`
	City       string                                              `json:"city,omitempty"`
	Detail     string                                              `json:"detail,omitempty"`
	Optional   string                                              `json:"optional,omitempty"`
	Recipient  PaymentsConfirmInfoShippingAddressRecipientResponse `json:"recipient,omitempty"`
}

type PaymentsConfirmInfoShippingResponse

type PaymentsConfirmInfoShippingResponse struct {
	MethodID  string                                     `json:"methodId"`
	FeeAmount int                                        `json:"feeAmount"`
	Address   PaymentsConfirmInfoShippingAddressResponse `json:"address"`
}

type PaymentsConfirmRequest

type PaymentsConfirmRequest struct {
	Amount   int    `json:"amount"`
	Currency string `json:"currency"`
}

Amount: [form.amount != sum(packages[].amount) + sum(packages[].userFee) + shippingFee]

type PaymentsConfirmResponse

type PaymentsConfirmResponse struct {
	ReturnCode    string                      `json:"returnCode"`
	ReturnMessage string                      `json:"returnMessage"`
	Info          PaymentsConfirmInfoResponse `json:"info"`
	Amount        int                         `json:"amount"`
	Currency      string                      `json:"currency"`
}

type PaymentsDetailsInfoPackagesProductsResponse

type PaymentsDetailsInfoPackagesProductsResponse struct {
	ID            string `json:"id"`
	Name          string `json:"name"`
	ImageURL      string `json:"imageUrl"`
	Quantity      int    `json:"quantity"`
	Price         int    `json:"price"`
	OriginalPrice int    `json:"originalPrice"`
}

type PaymentsDetailsInfoPackagesResponse

type PaymentsDetailsInfoPackagesResponse struct {
	ID            string                                        `json:"id"`
	Amount        int                                           `json:"amount"`
	UserFeeAmount int                                           `json:"userFeeAmount"`
	Name          string                                        `json:"name"`
	Products      []PaymentsDetailsInfoPackagesProductsResponse `json:"products"`
}

type PaymentsDetailsInfoPayInfoResponse

type PaymentsDetailsInfoPayInfoResponse struct {
	Method string `json:"method"` // CREDIT_CARD, BALANCE, DISCOUNT
	Amount int    `json:"amount"` // sum(info[].payInfo[].amount) – sum(refundList[].refundAmount)
}

type PaymentsDetailsInfoRefundListResponse

type PaymentsDetailsInfoRefundListResponse struct {
	RefundTransactionID   int64     `json:"refundTransactionId"`
	TransactionType       string    `json:"transactionType"` // PAYMENT_REFUND, PARTIAL_REFUND
	RefundAmount          int       `json:"refundAmount"`
	RefundTransactionDate time.Time `json:"refundTransactionDate"`
}

type PaymentsDetailsInfoResponse

type PaymentsDetailsInfoResponse struct {
	TransactionID           int64                                   `json:"transactionId"`
	TransactionDate         time.Time                               `json:"transactionDate"`
	TransactionType         string                                  `json:"transactionType"`
	PayStatus               string                                  `json:"payStatus"` // AUTHORIZATION, VOIDED_AUTHORIZATION, EXPIRED_AUTHORIZATION
	ProductName             string                                  `json:"productName"`
	MerchantName            string                                  `json:"merchantName"`
	Currency                string                                  `json:"currency"`
	AuthorizationExpireDate time.Time                               `json:"authorizationExpireDate"`
	PayInfo                 []PaymentsDetailsInfoPayInfoResponse    `json:"payInfo"`
	RefundList              []PaymentsDetailsInfoRefundListResponse `json:"refundList"` // in case of `Transaction` type
	OriginalTransactionID   int64                                   `json:"originalTransactionId"`
	Packages                []PaymentsDetailsInfoPackagesResponse   `json:"packages"`
	Shipping                PaymentsDetailsInfoShippingResponse     `json:"shipping"`
}

type PaymentsDetailsInfoShippingAddressRecipientResponse

type PaymentsDetailsInfoShippingAddressRecipientResponse struct {
	FirstName         string `json:"firstName"`
	LastName          string `json:"lastName"`
	FirstNameOptional string `json:"firstNameOptional"`
	LastNameOptional  string `json:"lastNameOptional"`
	Email             string `json:"email"`
	PhoneNo           string `json:"phoneNo"`
}

type PaymentsDetailsInfoShippingAddressResponse

type PaymentsDetailsInfoShippingAddressResponse struct {
	Country    string                                              `json:"country"`
	PostalCode string                                              `json:"postalCode"`
	State      string                                              `json:"state"`
	City       string                                              `json:"city"`
	Detail     string                                              `json:"detail"`
	Optional   string                                              `json:"optional"`
	Recipient  PaymentsDetailsInfoShippingAddressRecipientResponse `json:"recipient"`
}

type PaymentsDetailsInfoShippingResponse

type PaymentsDetailsInfoShippingResponse struct {
	MethodID  string                                     `json:"methodId"`
	FeeAmount int                                        `json:"feeAmount"`
	Address   PaymentsDetailsInfoShippingAddressResponse `json:"address"`
}

type PaymentsDetailsRequest

type PaymentsDetailsRequest struct {
	TransactionIDs []int64  ``
	OrderIDs       []string ``
	Fields         string   ``
}

if assign `TransactionIDs` and `OrderIDs` both at the same time, they should mean for the same record (like `AND` query).

type PaymentsDetailsResponse

type PaymentsDetailsResponse struct {
	ReturnCode    string                        `json:"returnCode"`
	ReturnMessage string                        `json:"returnMessage"`
	Info          []PaymentsDetailsInfoResponse `json:"info"`
}

type PaymentsInfoPaymentURLResponse

type PaymentsInfoPaymentURLResponse struct {
	Web string `json:"web"`
	App string `json:"app"`
}

type PaymentsInfoResponse

type PaymentsInfoResponse struct {
	TransactionID      int64                          `json:"transactionId"`
	PaymentAccessToken string                         `json:"paymentAccessToken"`
	PaymentURL         PaymentsInfoPaymentURLResponse `json:"paymentUrl"`
}

type PaymentsOptionsDisplayRequest

type PaymentsOptionsDisplayRequest struct {
	Locale                 string `json:"locale,omitempty"` // en, ja, ko, th, zh_TW, zh_CN
	CheckConfirmURLBrowser bool   `json:"checkConfirmUrlBrowser,omitempty"`
}

type PaymentsOptionsExtraRequest

type PaymentsOptionsExtraRequest struct {
	BranchName string `json:"branchName,omitempty"`
	BranchID   string `json:"branchId,omitempty"`
}

type PaymentsOptionsFamilyServiceAddFriendsRequest

type PaymentsOptionsFamilyServiceAddFriendsRequest struct {
	AddType string   `json:"type,omitempty"` // line@
	IDs     []string `json:"ids,omitempty"`
}

type PaymentsOptionsFamilyServiceRequest

type PaymentsOptionsFamilyServiceRequest struct {
	AddFriends []PaymentsOptionsFamilyServiceAddFriendsRequest `json:"addFriends"`
}

type PaymentsOptionsPaymentRequest

type PaymentsOptionsPaymentRequest struct {
	Capture bool   `json:"capture,omitempty"`
	PayType string `json:"payType,omitempty"` // NORMAL, PREAPPROVED
}

type PaymentsOptionsRequest

type PaymentsOptionsRequest struct {
	Payment       PaymentsOptionsPaymentRequest       `json:"payment"`
	Display       PaymentsOptionsDisplayRequest       `json:"display"`
	Shipping      PaymentsOptionsShippingRequest      `json:"shipping"`
	FamilyService PaymentsOptionsFamilyServiceRequest `json:"familyService"`
	Extra         PaymentsOptionsExtraRequest         `json:"extra"`
}

type PaymentsOptionsShippingAddressRecipientRequest

type PaymentsOptionsShippingAddressRecipientRequest struct {
	FirstName         string `json:"firstName,omitempty"`
	LastName          string `json:"lastName,omitempty"`
	FirstNameOptional string `json:"firstNameOptional,omitempty"`
	LastNameOptional  string `json:"lastNameOptional,omitempty"`
	Email             string `json:"email,omitempty"`
	PhoneNo           string `json:"phoneNo,omitempty"`
}

type PaymentsOptionsShippingAddressRequest

type PaymentsOptionsShippingAddressRequest struct {
	Country    string                                         `json:"country,omitempty"`
	PostalCode string                                         `json:"postalCode,omitempty"`
	State      string                                         `json:"state,omitempty"`
	City       string                                         `json:"city,omitempty"`
	Detail     string                                         `json:"detail,omitempty"`
	Optional   string                                         `json:"optional,omitempty"`
	Recipient  PaymentsOptionsShippingAddressRecipientRequest `json:"recipient,omitempty"`
}

type PaymentsOptionsShippingRequest

type PaymentsOptionsShippingRequest struct {
	ShippintType   string                                `json:"type,omitempty"`      // NO_SHIPPING, FIXED_ADDRESS, SHIPPING
	FeeAmount      string                                `json:"feeAmount,omitempty"` //why string?
	FeeInquiryURL  string                                `json:"feeInquiryUrl,omitempty"`
	FeeInquiryType string                                `json:"feeInquiryType,omitempty"` // CONDITION, FIXED
	Address        PaymentsOptionsShippingAddressRequest `json:"address"`
}

type PaymentsPackageProductRequest

type PaymentsPackageProductRequest struct {
	ID            string `json:"id,omitempty"`
	Name          string `json:"name"`
	ImageURL      string `json:"imageUrl,omitempty"`
	Quantity      int    `json:"quantity"`
	Price         int    `json:"price"`
	OriginalPrice int    `json:"originalPrice,omitempty"`
}

`Name` required `Quantity` required `Price` required

type PaymentsPackageRequest

type PaymentsPackageRequest struct {
	ID       string                          `json:"id"`
	Amount   int                             `json:"amount"`
	UserFee  int                             `json:"userFee,omitempty"`
	Name     string                          `json:"name"`
	Products []PaymentsPackageProductRequest `json:"products"`
}

`Id` required `Amount` required, valid amount `packages[].amount != sum(packages[].products[].quantity * packages[].products[].price)` `Name` required

type PaymentsRedirectUrlsRequest

type PaymentsRedirectUrlsRequest struct {
	AppPackageName string `json:"appPackageName,omitempty"`
	ConfirmURL     string `json:"confirmUrl"`
	ConfirmURLType string `json:"confirmUrlType,omitempty"`
	CancelURL      string `json:"cancelUrl"`
}

NOTE: for the behavior of `ConfirmUrl`, when `ConfirmUrlType` set to `PaymentsConfirmUrlTypeClient`, LINE server will send user to the `ConfirmUrl` with `transactionId`. `orderID` won't send for this case. the exception is, when user use *QR scanner* at the `waitPreLogin` page (login by LINE account or QR Code scan page) server will send user to `ConfirmUrl` with `orderID` `ConfirmUrl` required `CancelUrl` required

type PaymentsRequest

type PaymentsRequest struct {
	Amount       int                         `json:"amount"`
	Currency     string                      `json:"currency"`
	OrderID      string                      `json:"orderId"`
	Packages     []PaymentsPackageRequest    `json:"packages"`
	RedirectUrls PaymentsRedirectUrlsRequest `json:"redirectUrls"`
	Options      PaymentsOptionsRequest      `json:"options"`
}

`Amount` required, valid amount `form.amount != sum(packages[].amount) + sum(packages[].userFee) + shippingFee` `Currency` required, is ISO 4217, supported: USD, JPY, TWD, THB `OrderId` required if `Capture` true: only need to call `Confirm API` to process payments. false: call `Confirm API` and then `Capture API`

type PaymentsResponse

type PaymentsResponse struct {
	ReturnCode    string               `json:"returnCode"`
	ReturnMessage string               `json:"returnMessage"`
	Info          PaymentsInfoResponse `json:"info"`
}

response

type Signer

type Signer struct {
	ChannelId string
}

func (Signer) SignWithBody

func (v3 Signer) SignWithBody(r *http.Request, channelSecret string, requestBody string) (header http.Header, err error)

SignWithBody implements API Authentication in `https://pay.line.me/developers/apis/onlineApis` HTTP Method : POST Signature = Base64(HMAC-SHA256(Your ChannelSecret, (Your ChannelSecret + URL Path + RequestBody + nonce)))

HTTP Method : GET Signature = Base64(HMAC-SHA256(Your ChannelSecret, (Your ChannelSecret + URL Path + Query String + nonce))) Query String : A query string except ? (Example: Name1=Value1&Name2=Value2...)

Directories

Path Synopsis
examples
cmd

Jump to

Keyboard shortcuts

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