amazonpay

package module
v0.0.0-...-2fc10fb Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2020 License: MIT Imports: 19 Imported by: 3

README

Amazon Pay Go SDK

Amazon Pay SDK for Golang

Install

go get github.com/conku/amazon-pay-sdk-go

Usage

import amazonpay "github.com/conku/amazon-pay-sdk-go"

func main() {
  var client = amazonpay.New(&amazonpay.Config{
    MerchantID: "my merchant id",
    AccessKey:  "my access key",
    SecretKey:  "my secret key",
    Sandbox:    true,
    Region:     "jp",
  })

  // Set order details such as order amount and explanation in Order Reference
  client.SetOrderReferenceDetails(orderReferenceID, amazonpay.OrderReferenceAttributes) (amazonpay.SetOrderReferenceDetailsResult, error)

  // confirm order details
  client.ConfirmOrderReference(orderReferenceID) error

  // Returns the details and current state of the Order Reference object
  client.GetOrderReferenceDetails(orderReferenceID, addressToken) (amazonpay.GetOrderReferenceDetailsResponse, error)

  // Process secures the funds specified for the payment method stored in the Order Reference
  client.Authorize(orderReferenceID, authorizationReferenceID, amount, amazonpay.AuthorizeInput) (amazonpay.AuthorizeResponse, error)

  // Returns the total authorized amount for authorization status and authorization
  client.GetAuthorizationDetails(authorizationID) (amazonpay.GetAuthorizationDetailsResponse, error)

  // CloseAuthorization Close authorization
  client.CloseAuthorization(authorizationID, closureReason) error

  // Request funds from the authorized payment method
  client.Capture(authorizationID, captureReferenceID, captureAmount, amazonpay.CaptureInput) (amazonpay.CaptureResponse, error)

  // Returns the detailed sales request status and the total amount refunded by sales request
  client.GetCaptureDetails(captureID) (amazonpay.GetCaptureDetailsResponse, error)

  // Complete order reference and will not be able to generate a new authorization from this Order Reference
  client.CloseOrderReference(orderReferenceID, closureReason) error

  // CancelOrderReference Cancels a previously confirmed order reference
  client.CancelOrderReference(orderReferenceID, reason) error

  // Refund refund the funds requested
  client.Refund(captureID, refundReferenceID, refundAmount, amazonpay.RefundInput) (amazonpay.RefundResponse, error)

  // Get refund details
  client.GetRefundDetails(refundID) (amazonpay.GetRefundDetailsResponse, error)
}

Verify IPN Notification

Verify ipn notification

amazonpay.VerifyIPNRequest(req)

Demo

We have deployed a demo that integrated Amazon Pay sandbox mode, visit it here: https://demo.getqor.com

You can place orders with our Amazon sandbox account: demo@getqor.com / qordemo

After placed orders, you can manage them via our admin interface, like take auth, capture, refund orders, the admin interface is generated with QOR Admin

Source code of this demo

https://github.com/conku/qor-example

License

Released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// OAuthEndpoint oauth endpoint
	OAuthEndpoint = "https://api.amazon.com"
	// OAuthSandboxEndpoint oauth endpoint for sandbox env
	OAuthSandboxEndpoint = "https://api.sandbox.amazon.com"
)
View Source
var MWSServiceURLs = map[string]string{
	"eu": "mws-eu.amazonservices.com",
	"na": "mws.amazonservices.com",
	"jp": "mws.amazonservices.jp",
}

MWSServiceURLs mwsservice urls

View Source
var RegionMappings = map[string]string{
	"de": "eu",
	"uk": "eu",
	"us": "na",
	"jp": "jp",
}

RegionMappings region mapping

Functions

This section is empty.

Types

type APIError

type APIError struct {
	XMLName xml.Name `xml:"ErrorResponse"`
	Type    string   `xml:"Error>Type"`
	Code    string   `xml:"Error>Code"`
	Message string   `xml:"Error>Message"`
}

APIError Amazon Pay API Error definition

func (APIError) Error

func (apiError APIError) Error() string

type Address

type Address struct {
	Name                                     string
	AddressLine1, AddressLine2, AddressLine3 string
	City                                     string
	Country                                  string
	District                                 string
	StateOrRegion                            string
	PostalCode                               string
	CountryCode                              string
	Phone                                    string
}

Address postal address information

type AmazonPay

type AmazonPay struct {
	*Config
}

AmazonPay amazon pay

func (*AmazonPay) Authorize

func (amazonPay *AmazonPay) Authorize(orderReferenceID string, authorizationReferenceID string, amount Price, input AuthorizeInput) (result AuthorizeResponse, err error)

Authorize process secures the funds specified for the payment method stored in the Order Reference.

func (*AmazonPay) CancelOrderReference

func (amazonPay *AmazonPay) CancelOrderReference(orderReferenceID string, reason string) error

CancelOrderReference Cancels a previously confirmed order reference.

func (*AmazonPay) Capture

func (amazonPay *AmazonPay) Capture(authorizationID string, captureReferenceID string, captureAmount Price, input CaptureInput) (result CaptureResponse, err error)

Capture request funds from the authorized payment method.

func (*AmazonPay) CloseAuthorization

func (amazonPay *AmazonPay) CloseAuthorization(authorizationID string, closureReason string) error

CloseAuthorization Close authorization

func (*AmazonPay) CloseOrderReference

func (amazonPay *AmazonPay) CloseOrderReference(orderReferenceID string, closureReason string) error

CloseOrderReference complete order reference and will not be able to generate a new authorization from this Order Reference.

func (*AmazonPay) ConfirmOrderReference

func (amazonPay *AmazonPay) ConfirmOrderReference(orderReferenceID string) error

ConfirmOrderReference confirm order details

func (*AmazonPay) GetAuthorizationDetails

func (amazonPay *AmazonPay) GetAuthorizationDetails(authorizationID string) (result GetAuthorizationDetailsResponse, err error)

GetAuthorizationDetails returns the total authorized amount for authorization status and authorization.

func (*AmazonPay) GetCaptureDetails

func (amazonPay *AmazonPay) GetCaptureDetails(captureID string) (result GetCaptureDetailsResponse, err error)

GetCaptureDetails returns the detailed sales request status and the total amount refunded by sales request.

func (*AmazonPay) GetOrderReferenceDetails

func (amazonPay *AmazonPay) GetOrderReferenceDetails(orderReferenceID string, addressToken string) (result GetOrderReferenceDetailsResponse, err error)

GetOrderReferenceDetails Returns the details and current state of the Order Reference object.

func (*AmazonPay) GetProfile

func (amazonPay *AmazonPay) GetProfile(token string) (profile Profile, err error)

GetProfile get user profile

func (*AmazonPay) GetRefundDetails

func (amazonPay *AmazonPay) GetRefundDetails(refundID string) (result GetRefundDetailsResponse, err error)

GetRefundDetails get refund details

func (*AmazonPay) Post

func (amazonPay *AmazonPay) Post(params Params, response interface{}) error

Post post API info

func (*AmazonPay) Refund

func (amazonPay *AmazonPay) Refund(captureID string, refundReferenceID string, refundAmount Price, input RefundInput) (result RefundResponse, err error)

Refund refund the funds requested

func (*AmazonPay) SetOrderReferenceDetails

func (amazonPay *AmazonPay) SetOrderReferenceDetails(orderReferenceID string, attrs OrderReferenceAttributes) (result SetOrderReferenceDetailsResult, err error)

SetOrderReferenceDetails set order details such as order amount and explanation in Order Reference

func (*AmazonPay) Sign

func (amazonPay *AmazonPay) Sign(message string) string

Sign sign messages

type AmazonPayService

type AmazonPayService interface {
	GetProfile(token string) (profile Profile, err error)
	SetOrderReferenceDetails(orderReferenceID string, attrs OrderReferenceAttributes) (result SetOrderReferenceDetailsResult, err error)
	ConfirmOrderReference(orderReferenceID string) error
	GetOrderReferenceDetails(orderReferenceID string, addressToken string) (result GetOrderReferenceDetailsResponse, err error)
	Authorize(orderReferenceID string, authorizationReferenceID string, amount Price, input AuthorizeInput) (result AuthorizeResponse, err error)
	GetAuthorizationDetails(authorizationID string) (result GetAuthorizationDetailsResponse, err error)
	CloseAuthorization(authorizationID string, closureReason string) error
	Capture(authorizationID string, captureReferenceID string, captureAmount Price, input CaptureInput) (result CaptureResponse, err error)
	GetCaptureDetails(captureID string) (result GetCaptureDetailsResponse, err error)
	CloseOrderReference(orderReferenceID string, closureReason string) error
	CancelOrderReference(orderReferenceID string, reason string) error
	Refund(captureID string, refundReferenceID string, refundAmount Price, input RefundInput) (result RefundResponse, err error)
	GetRefundDetails(refundID string) (result GetRefundDetailsResponse, err error)
	Post(params Params, response interface{}) error
	Sign(message string) string
}

func New

func New(config *Config) AmazonPayService

New initialize amazon pay

type AuthorizationDetails

type AuthorizationDetails struct {
	AmazonAuthorizationID    string `xml:"AmazonAuthorizationId"`
	AuthorizationReferenceID string `xml:"AuthorizationReferenceId"`
	SellerAuthorizationNote  string
	AuthorizationAmount      Price
	CaptureAmount            Price
	AuthorizationFee         Price
	IDList                   []string `xml:"IdList"`
	CreationTimestamp        *time.Time
	ExpirationTimestamp      *time.Time
	AuthorizationStatus      Status
	SoftDecline              bool
	CaptureNow               bool
	SoftDescriptor           string
}

AuthorizationDetails details and status of the authorization object, including sales charge amount.

type AuthorizationNotification

type AuthorizationNotification struct {
	AuthorizationDetails AuthorizationDetails
}

AuthorizationNotification authorization notification data

type AuthorizeInput

type AuthorizeInput struct {
	SellerAuthorizationNote string
	TransactionTimedOut     uint
	CaptureNow              bool
	SoftDecriptor           string
}

AuthorizeInput authorize input struct

type AuthorizeResponse

type AuthorizeResponse struct {
	AuthorizeResult struct {
		AuthorizationDetails AuthorizationDetails
	}
	ResponseMetadata ResponseMetadata
}

AuthorizeResponse authorize response

type Buyer

type Buyer struct {
	Name  string
	Email string
	Phone string
}

Buyer buyer info

type CaptureDetails

type CaptureDetails struct {
	AmazonCaptureID    string `xml:"AmazonCaptureId"`
	CaptureReferenceID string `xml:"CaptureReferenceId"`
	SellerCaptureNote  string
	CaptureAmount      Price
	RefundAmount       Price
	CaptureFee         Price
	IDList             []string `xml:"IdList"`
	CreationTimestamp  *time.Time
	CaptureStatus      Status
	SoftDescriptor     string
}

CaptureDetails the details of the sales claim object and its current state.

type CaptureInput

type CaptureInput struct {
	SellerCaptureNote string
	SoftDecriptor     string
}

CaptureInput capture input struct

type CaptureNotification

type CaptureNotification struct {
	CaptureDetails CaptureDetails
}

CaptureNotification capture notification

type CaptureResponse

type CaptureResponse struct {
	CaptureResult struct {
		CaptureDetails CaptureDetails
	}
	ResponseMetadata ResponseMetadata
}

CaptureResponse capture response

type Config

type Config struct {
	MerchantID    string
	AccessKey     string
	SecretKey     string
	Sandbox       bool
	Region        string
	CurrencyCode  string
	Endpoint      string
	OAuthEndpoint string
	ModePath      string
	APIVersion    string
	PlatformID    string
}

Config Amazon Pay Config

Note on 'PlatformID':

According to AmazonPay docs, 'PlatformID' is the MerchatID, which is also referenced as SellerID
https://developer.amazon.com/ja/docs/amazon-pay-api/setorderattributes.html

But, in real life business, AmazonPay vendor may provide a different PlatformID for tracking incentives
So you can set this seperately

type Constraint

type Constraint struct {
	ConstraintID string `xml:"ConstraintId"`
	Description  string
}

Constraint represents a mistake or error information of a Billing Agreement or Order Reference object.

type Destination

type Destination struct {
	DestinationType     string
	PhysicalDestination Address
}

Destination the address selected by the buyer via the address book widget.

type GetAuthorizationDetailsResponse

type GetAuthorizationDetailsResponse struct {
	GetAuthorizationDetailsResult struct {
		AuthorizationDetails
	}
	ResponseMetadata ResponseMetadata
}

GetAuthorizationDetailsResponse get authorization detail response

type GetCaptureDetailsResponse

type GetCaptureDetailsResponse struct {
	GetCaptureDetailsResult struct {
		CaptureDetails CaptureDetails
	}
	ResponseMetadata ResponseMetadata
}

GetCaptureDetailsResponse get capture details response

type GetOrderReferenceDetailsResponse

type GetOrderReferenceDetailsResponse struct {
	GetOrderReferenceDetailsResult struct {
		OrderReferenceDetails OrderReferenceDetails
	}
	ResponseMetadata ResponseMetadata
}

GetOrderReferenceDetailsResponse details and current state of the Order Reference object.

type GetRefundDetailsResponse

type GetRefundDetailsResponse struct {
	GetRefundDetailsResult struct {
		RefundDetails RefundDetails
	}
	ResponseMetadata ResponseMetadata
}

GetRefundDetailsResponse get refund detail response

type IPN

type IPN struct {
	Type             string
	MessageID        string `json:"MessageId"`
	TopicArn         string
	Timestamp        string
	SignatureVersion string
	Signature        string
	SigningCertURL   string
	UnsubscribeURL   string
	Message          string
}

IPN ipn message

func VerifyIPNRequest

func VerifyIPNRequest(req *http.Request) (*IPN, bool)

VerifyIPNRequest verify IPN request message

func (IPN) GetMessage

func (ipn IPN) GetMessage() (Message, error)

GetMessage get IPN message

func (IPN) GetNotification

func (ipn IPN) GetNotification() (interface{}, error)

GetNotification get notification message

type Message

type Message struct {
	NotificationReferenceID string `json:"NotificationReferenceId"`
	NotificationType        string
	SellerID                string `json:"SellerId"`
	ReleaseEnvironment      string
	Version                 string
	NotificationData        string
	Timestamp               string
}

Message ipn message struct

func (Message) GetAuthorizationNotification

func (msg Message) GetAuthorizationNotification() (AuthorizationNotification, error)

GetAuthorizationNotification get authorization notification data (notification type: PaymentAuthorize)

func (Message) GetCaptureNotification

func (msg Message) GetCaptureNotification() (CaptureNotification, error)

GetCaptureNotification get capture notification data (notification type: PaymentCapture)

func (Message) GetOrderReferenceNotification

func (msg Message) GetOrderReferenceNotification() (OrderReferenceNotification, error)

GetOrderReferenceNotification get order reference notification data (notification type: OrderReferenceNotification)

func (Message) GetRefundNotification

func (msg Message) GetRefundNotification() (RefundNotification, error)

GetRefundNotification get refund notification data (notification type: PaymentRefund)

type OAuthResponseError

type OAuthResponseError struct {
	ErrorDescription string `json:"error_description"`
	Error            string `json:"error"`
}

OAuthResponseError oauth error response

type OrderReferenceAttributes

type OrderReferenceAttributes struct {
	OrderTotal            OrderTotal
	PlatformID            string `xml:"PlatformId"`
	SellerNote            string
	SellerOrderAttributes SellerOrderAttributes
}

OrderReferenceAttributes attribute of the Order Reference object specified by the seller.

type OrderReferenceDetails

type OrderReferenceDetails struct {
	AmazonOrderReferenceID string `xml:"AmazonOrderReferenceId"`
	Buyer                  Buyer
	OrderTotal             OrderTotal
	SellerNote             string
	PlatformID             string `xml:"PlatformId"`
	Destination            Destination
	ReleaseEnvironment     string
	SellerOrderAttributes  SellerOrderAttributes
	OrderReferenceStatus   OrderReferenceStatus
	Constraints            []Constraint
	CreationTimestamp      *time.Time
	ExpirationTimestamp    *time.Time
	IDList                 []string `xml:"IdList"`
}

OrderReferenceDetails details and current state of the Order Reference object.

type OrderReferenceNotification

type OrderReferenceNotification struct {
	OrderReference OrderReferenceDetails
}

OrderReferenceNotification order reference notification data

type OrderReferenceStatus

type OrderReferenceStatus struct {
	State               string
	LastUpdateTimestamp *time.Time
	ReasonCode          string
	ReasonDescription   string
}

OrderReferenceStatus the current state of the Order Reference object.

type OrderTotal

type OrderTotal struct {
	CurrencyCode string
	Amount       string
}

OrderTotal total order amount presented in this Order Reference.

type Params

type Params map[string]interface{}

Params API params

func (Params) Get

func (params Params) Get(key string) (interface{}, bool)

Get get value from params

func (Params) Set

func (params Params) Set(key string, value interface{})

Set set value to params

func (Params) Sign

func (params Params) Sign() string

Sign sign params

type Price

type Price struct {
	Amount       string
	CurrencyCode string
}

Price currency type and amount.

type Profile

type Profile struct {
	UserID string `json:"user_id"`
	Name   string `json:"name"`
	Email  string `json:"email"`
}

Profile user profile

type RefundDetails

type RefundDetails struct {
	AmazonRefundID    string `xml:"AmazonRefundId"`
	RefundReferenceID string `xml:"RefundReferenceId"`
	SellerRefundNote  string
	RefundType        string
	RefundAmount      Price
	FeeRefunded       Price
	CreationTimestamp *time.Time
	RefundStatus      Status
	SoftDescriptor    string
}

RefundDetails details and the current state of the refund object.

type RefundInput

type RefundInput struct {
	SellerRefundNote string
	SoftDescriptor   string
}

RefundInput refund input struct

type RefundNotification

type RefundNotification struct {
	RefundDetails RefundDetails
}

RefundNotification refund notification

type RefundResponse

type RefundResponse struct {
	RefundResult struct {
		RefundDetails RefundDetails
	}
	ResponseMetadata ResponseMetadata
}

RefundResponse get refund response

type ResponseMetadata

type ResponseMetadata struct {
	RequestID string `xml:"RequestId"`
}

ResponseMetadata respones meta data

type SellerOrderAttributes

type SellerOrderAttributes struct {
	SellerOrderID     string `xml:"SellerOrderId"`
	StoreName         string
	CustomInformation string
}

SellerOrderAttributes provides detailed information on the Order Reference object

type SetOrderReferenceDetailsResult

type SetOrderReferenceDetailsResult struct {
	SetOrderReferenceDetailsResult struct {
		OrderReferenceDetails OrderReferenceDetails
	}
	ResponseMetadata ResponseMetadata
}

SetOrderReferenceDetailsResult set order reference detail

type Status

type Status struct {
	State               string
	LastUpdateTimestamp *time.Time
	ReasonCode          string
	ReasonDescription   string
}

Status represents the current status of authorization object, sales request object, refund object.

Jump to

Keyboard shortcuts

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