paypal

package module
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2021 License: MIT Imports: 14 Imported by: 0

README

payment.PayPal

Implementing PayPal as a payment gateway in Golang

Documentation

Index

Constants

View Source
const (
	PREPAID_GATEWAY uint = iota
	BILLINGAGREEMENT_GATEWAY
)

Variables

View Source
var (
	// success (200 OK)
	PAYMENT_OK = api.MessageResponse(api.SUCCESS, "PAYMENT_OK")

	// cancel (200 OK)
	BUYER_PAYPAL_CANCEL = api.MessageResponse(api.CANCELED, "BUYER_PAYPAL_CANCEL")

	// error
	// 400 Bad Request
	BAD_REQUEST = api.MessageResponse(api.ERROR, "BAD_REQUEST")

	// 503 Service Unavailable
	BUYER_PAYPAL_ERROR = api.MessageResponse(api.ERROR, "BUYER_PAYPAL_ERROR")

	// 409 Conflict
	PAYMENT_NOT_APPROVED = api.MessageResponse(api.ERROR, "PAYMENT_NOT_APPROVED")

	// 500 Internal Server Error
	SERVER_BAD_DATABASE = api.MessageResponse(api.ERROR, "SERVER_BAD_DATABASE")

	// 500 Internal Server Error
	SERVER_PAYPAL_BAD_AUTH = api.MessageResponse(api.ERROR, "SERVER_PAYPAL_BAD_AUTH")

	// PayPal gives a bad order according to the user-reported order ID
	// reason could be:
	// - Can't get such order from PayPal (500)
	// - The order is not intact: payment item or price tainted (400)
	// - ReferenceID not match (400)
	// - Price can't be parsed to float (500)
	SERVER_PAYPAL_BAD_ORDER = api.MessageResponse(api.ERROR, "SERVER_PAYPAL_BAD_ORDER")
)
View Source
var (
	ErrBadInitConf    error = errors.New("paypal: bad initConf")
	ErrOrderNotPaid   error = errors.New("paypal: order is not in paid state")
	ErrRepeatedRefund error = errors.New("paypal: refund amount exceeds paid amount")
	ErrNoCaptureID    error = errors.New("paypal: no capture ID associated or there was an error when fetching capture ID")

	ExampleInitConf = map[string]string{

		"clientID": `ABCD`,
		"secretID": `EFGHIJKLMNOPQRST`,
		"apiBase":  `https://api-m.sandbox.paypal.com`,

		"orderSqlTable": `prepaid_paypal_orders_2`,

		"returnURL": `https://ulysses.tunnel.work/billing.html`,
	}
)
View Source
var DefaultPrepaidConfig = PrepaidConfig{
	ClientID: "<YOUR_CLIENT_ID>",
	SecretID: "<YOUR_SECRET>",
	ApiBase:  `https://api-m.sandbox.paypal.com`,
}

Functions

func NewPrepaidGateway

func NewPrepaidGateway(db *sql.DB, instanceID string, initConf interface{}) (payment.PrepaidGateway, error)

NewPrepaidGateway() is a payment.PrepaidGatewayGen

Types

type PrepaidConfig

type PrepaidConfig struct {
	ClientID string `json:"client_id"`
	SecretID string `json:"secret_id"`
	ApiBase  string `json:"api_base"` // https://api-m.sandbox.paypal.com
}

func LoadPrepaidConfig

func LoadPrepaidConfig(db *sql.DB, tblPrefix string, instanceID string) (PrepaidConfig, error)

type PrepaidGateway

type PrepaidGateway struct {

	// Handler func used to notify the Ulysses server
	UpdateHandler *func(referenceID string, newResult payment.PaymentResult)
	// contains filtered or unexported fields
}

func (*PrepaidGateway) CheckoutForm

func (pg *PrepaidGateway) CheckoutForm(pr payment.PaymentRequest) (formRenderParams map[string]interface{}, err error)

CheckoutForm() is called when frontend requests a Checkout Form to be rendered

func (*PrepaidGateway) IsRefundable

func (pg *PrepaidGateway) IsRefundable(referenceID string) bool

IsRefundable() checks if an order is eligible for at least a partial refund.

func (*PrepaidGateway) OnStatusChange

func (pg *PrepaidGateway) OnStatusChange(UpdateHandler *func(referenceID string, newResult payment.PaymentResult)) error

func (*PrepaidGateway) PaymentResult

func (pg *PrepaidGateway) PaymentResult(referenceID string) (result payment.PaymentResult, err error)

PaymentResult() is called by Ulysses to ACTIVELY verify an order's payment status on the contradictory, please see OnStatusChange() where Ulysses waits for payment gateway to report the payment result.

func (*PrepaidGateway) Refund

func (pg *PrepaidGateway) Refund(rr payment.RefundRequest) error

Refund the transaction according to a request built by caller

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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