Documentation ¶
Overview ¶
Package ecom provides a Client and supporting types to consume and interact with the Vipps Ecom V2 API
Index ¶
- func HandleConsentRemoval(cb func(uid string)) http.HandlerFunc
- func HandleShippingDetails(authToken string, ...) http.HandlerFunc
- func HandleTransactionUpdate(authToken string, cb func(t TransactionUpdate)) http.HandlerFunc
- type Address
- type AddressType
- type CancelPaymentCommand
- type CancelledPayment
- type CapturePaymentCommand
- type CapturedPayment
- type Client
- func (c *Client) CancelPayment(ctx context.Context, cmd CancelPaymentCommand) (*CancelledPayment, error)
- func (c *Client) CapturePayment(ctx context.Context, cmd CapturePaymentCommand) (*CapturedPayment, error)
- func (c *Client) GetPayment(ctx context.Context, orderID string) (*Payment, error)
- func (c *Client) InitiatePayment(ctx context.Context, cmd InitiatePaymentCommand) (*PaymentReference, error)
- func (c *Client) RefundPayment(ctx context.Context, cmd RefundPaymentCommand) (*RefundedPayment, error)
- type CustomerInfo
- type Doer
- type EcomAPIError
- type ErrEcom
- type InitiatePaymentCommand
- type MerchantInfo
- type Payment
- type PaymentReference
- type PaymentType
- type RefundPaymentCommand
- type RefundedPayment
- type ShippingCostRequest
- type ShippingCostResponse
- type ShippingDetails
- type StaticShippingMethod
- type Timestamp
- type Transaction
- type TransactionInfo
- type TransactionLogEntry
- type TransactionSummary
- type TransactionUpdate
- type UserDetails
- type YesNoEnum
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandleConsentRemoval ¶ added in v0.1.1
func HandleConsentRemoval(cb func(uid string)) http.HandlerFunc
HandleConsentRemoval returns a convenience http.HandlerFunc for receiving requests for user consent removals from Vipps. `cb` is called with the uid of the user to that wishes to have its consents and data removed.
func HandleShippingDetails ¶ added in v0.1.1
func HandleShippingDetails(authToken string, cb func(orderId string, req ShippingCostRequest) (ShippingCostResponse, error)) http.HandlerFunc
HandleShippingDetails returns a convenience http.HandlerFunc for responding to requests from Vipps to calculate shipping costs for an order.
The provided authToken, if not empty, will be matched with the `Authorization` header of the incoming requests. If they don't match, the request will fail.
func HandleTransactionUpdate ¶ added in v0.1.1
func HandleTransactionUpdate(authToken string, cb func(t TransactionUpdate)) http.HandlerFunc
HandleTransactionUpdate returns a convenience http.HandlerFunc for getting notifications from Vipps about transaction updates.
The provided authToken, if not empty, will be matched with the `Authorization` header of the incoming requests. If they don't match, the request will fail.
`cb` will be called with the TransactionUpdate. Please be aware that for payments of PaymentTypeRegular, the fields `ShippingDetails` and `UserDetails` will be nil.
Types ¶
type Address ¶
type Address struct { AddressLine1 string `json:"addressLine1"` AddressLine2 string `json:"addressLine2"` City string `json:"city"` Country string `json:"country"` PostCode string `json:"postCode"` }
Address represents a Customer's shipping address
type AddressType ¶ added in v0.1.1
type AddressType string
AddressType represents an address type
const ( AddressTypeHome AddressType = "H" AddressTypeBusiness AddressType = "B" )
List of values that AddressType can take
type CancelPaymentCommand ¶
type CancelPaymentCommand struct { OrderID string MerchantSerialNumber string TransactionText string }
CancelPaymentCommand represents the command used to cancel Vipps Ecom payments
type CancelledPayment ¶
type CancelledPayment struct { OrderID string `json:"orderId"` TransactionInfo TransactionInfo `json:"transactionInfo"` TransactionSummary TransactionSummary `json:"transactionSummary"` }
CancelledPayment represents a cancelled payment
type CapturePaymentCommand ¶
type CapturePaymentCommand struct { IdempotencyKey string OrderID string MerchantSerialNumber string Amount int TransactionText string }
CapturePaymentCommand represents the command used to capture Vipps Ecom payments
type CapturedPayment ¶
type CapturedPayment struct { OrderID string `json:"orderId"` TransactionInfo TransactionInfo `json:"transactionInfo"` TransactionSummary TransactionSummary `json:"transactionSummary"` }
CapturedPayment represents a captured Vipps Ecom payment
type Client ¶
Client represents an API client for the Vipps ecomm v2 API.
func NewClient ¶
func NewClient(config vipps.ClientConfig) *Client
NewClient returns a configured Client
func (*Client) CancelPayment ¶
func (c *Client) CancelPayment(ctx context.Context, cmd CancelPaymentCommand) (*CancelledPayment, error)
CancelPayment cancels an initiated payment. Errors for payments that are not in a cancellable state.
func (*Client) CapturePayment ¶
func (c *Client) CapturePayment(ctx context.Context, cmd CapturePaymentCommand) (*CapturedPayment, error)
CapturePayment captures reserved amounts on a Payment
func (*Client) GetPayment ¶
GetPayment gets a Payment.
func (*Client) InitiatePayment ¶
func (c *Client) InitiatePayment(ctx context.Context, cmd InitiatePaymentCommand) (*PaymentReference, error)
InitiatePayment initiates a new Payment and returns a reference to a resource hosted by Vipps where the payment flow can continue.
func (*Client) RefundPayment ¶
func (c *Client) RefundPayment(ctx context.Context, cmd RefundPaymentCommand) (*RefundedPayment, error)
RefundPayment refunds already captured amounts on a Payment.
type CustomerInfo ¶
type CustomerInfo struct { // MobileNumber is a Norwegian mobile phone number. 8 digits, no country // prefix MobileNumber int `json:"mobileNumber"` }
CustomerInfo represents information about a Vipps customer
type EcomAPIError ¶
type EcomAPIError struct { Group string `json:"errorGroup"` Message string `json:"errorMessage"` Code string `json:"errorCode"` }
EcomAPIError represents a single error returned from the Vipps Ecom API.
type ErrEcom ¶
type ErrEcom []EcomAPIError
ErrEcomm represents errors returned from the Vipps Ecom API.
type InitiatePaymentCommand ¶
type InitiatePaymentCommand struct { MerchantInfo MerchantInfo `json:"merchantInfo"` CustomerInfo CustomerInfo `json:"customerInfo"` Transaction Transaction `json:"transaction"` Scope []string `json:"scope"` }
InitiatePaymentCommand represents the command used to initiate Vipps Ecom payments
type MerchantInfo ¶
type MerchantInfo struct { // AuthToken, if set, will be used as the `Authorization` header of the // callback request that Vipps does to `CallbackURL` for transaction // updates. AuthToken string `json:"authToken,omitempty"` // MerchantSerialNumber uniquely represents a sales unit in the Vipps // system. MerchantSerialNumber string `json:"merchantSerialNumber"` // CallbackURL is a publicly reachable HTTP endpoint that will receive // transaction updates from Vipps. CallbackURL string `json:"callbackPrefix,omitempty"` // ConsentRemovalURL is a publicly reachable HTTP endpoint that will receive // requests for removal of user consents, for GDPR compliance. ConsentRemovalURL string `json:"consentRemovalPrefix,omitempty"` // RedirectURL is the URL clients are redirected to after completing the // payment flow in the Vipps app. RedirectURL string `json:"fallBack,omitempty"` // PaymentType selects the type of payment flow to use. If not provided, // `PaymentTypeRegular` is assumed by Vipps. PaymentType PaymentType `json:"paymentType,omitempty"` // IsApp signals whether the payment flow is initiated from a mobile app or // website. Returns a deep link url of the form `vipps://` if set to `true`. IsApp bool `json:"isApp,omitempty"` // ShippingDetailsURL is a publicly reachable HTTP endpoint that will // receive requests from Vipps to calculate shipping costs. ShippingDetailsURL string `json:"shippingDetailsPrefix,omitempty"` // ShippingMethods is a static list of shipping methods to present to the // user in the Vipps app. ShippingMethods []StaticShippingMethod `json:"staticShippingDetails,omitempty"` }
MerchantInfo represents a merchant configuration to use for Vipps Ecom payments
type Payment ¶
type Payment struct { OrderID string `json:"orderId"` ShippingDetails ShippingDetails `json:"shippingDetails,omitempty"` TransactionLog []TransactionLogEntry `json:"transactionLogHistory"` TransactionSummary TransactionSummary `json:"transactionSummary"` UserDetails UserDetails `json:"userDetails,omitempty"` }
Payment represents a Vipps payment.
type PaymentReference ¶
PaymentReference represents a reference to a Vipps payment
type PaymentType ¶
type PaymentType string
PaymentType is the type of payment flow to use for Vipps Ecom payments
const ( PaymentTypeRegular PaymentType = "eComm Regular Payment" PaymentTypeExpress PaymentType = "eComm Express Payment" )
List of values that PaymentType can take
type RefundPaymentCommand ¶
type RefundPaymentCommand struct { IdempotencyKey string OrderID string MerchantSerialNumber string TransactionText string Amount int }
RefundPaymentCommand represents the command used to refund Vipps Ecom payments
type RefundedPayment ¶
type RefundedPayment struct { OrderID string `json:"orderId"` TransactionInfo TransactionInfo `json:"transaction"` TransactionSummary TransactionSummary `json:"transactionSummary"` }
RefundedPayment represents a refunded Vipps Ecom payment
type ShippingCostRequest ¶ added in v0.1.1
type ShippingCostRequest struct { AddressID int `json:"addressId"` AddressLine1 string `json:"addressLine1"` AddressLine2 string `json:"addressLine2"` City string `json:"city"` Country string `json:"country"` PostCode string `json:"postCode"` AddressType AddressType `json:"addressType"` }
ShippingCostRequest is the request sent from Vipps to calculate shipping costs for an order.
type ShippingCostResponse ¶ added in v0.1.1
type ShippingCostResponse struct { AddressID int `json:"addressId"` OrderID string `json:"orderId"` ShippingDetails []StaticShippingMethod `json:"shippingDetails"` }
ShippingCostResponse is sent in response to a ShippingCostRequest
type ShippingDetails ¶
type ShippingDetails struct { Address Address `json:"address,omitempty"` ShippingCost int `json:"shippingCost,omitempty"` ShippingMethod string `json:"shippingMethod,omitempty"` ShippingMethodID string `json:"shippingMethodId,omitempty"` }
ShippingDetails represents details for a shipping method
type StaticShippingMethod ¶
type StaticShippingMethod struct { IsDefault YesNoEnum `json:"isDefault"` Priority int `json:"priority"` ShippingCost float64 `json:"shippingCost"` ShippingMethod string `json:"shippingMethod"` ShippingMethodID string `json:"shippingMethodId"` }
StaticShippingMethod represents a static shipping method represented to the user in the Vipps app.
type Timestamp ¶
Timestamp is a time.Time with a custom JSON marshaller.
func (Timestamp) MarshalJSON ¶
type Transaction ¶
type Transaction struct { // OrderID represents the order that this payment refers to. Must be unique // for each sales unit. OrderID string `json:"orderId"` // Amount is the amount (in cents) to be paid for the order. Amount int `json:"amount"` // TransactionText is the short message displayed to the user about the // payment in the Vipps app. TransactionText string `json:"transactionText"` // SkipLandingPage is a flag to disable the Vipps landing page and send a // push notification instantly. SkipLandingPage bool `json:"skipLandingPage"` }
Transaction represents details for a Vipps Ecom payment.
type TransactionInfo ¶
type TransactionInfo struct { Amount int `json:"amount"` Status string `json:"status"` Timestamp *time.Time `json:"timeStamp"` TransactionID string `json:"transactionId"` TransactionText string `json:"transactionText"` }
TransactionInfo represents details about a Transaction in the Vipps Ecom system.
type TransactionLogEntry ¶
type TransactionLogEntry struct { Amount int `json:"amount"` Operation string `json:"operation"` OperationSuccess bool `json:"operationSuccess"` RequestID string `json:"requestId"` Timestamp *time.Time `json:"timeStamp"` TransactionID string `json:"transactionId"` TransactionText string `json:"transactionText"` }
TransactionLogEntry represents the list of transactions associated with a payment
type TransactionSummary ¶
type TransactionSummary struct { CapturedAmount int `json:"capturedAmount"` RefundedAmount int `json:"refundedAmount"` RemainingAmountToCapture int `json:"remainingAmountToCapture"` RemainingAmountToRefund int `json:"remainingAmountToRefund"` BankIdentificationNumber int `json:"bankIdentificationNumber"` }
TransactionSummary represents a summary of captured, refunded and available amounts on a Vipps Ecom payment.
type TransactionUpdate ¶ added in v0.1.1
type TransactionUpdate struct { MerchantSerialNumber string `json:"merchantSerialNumber"` OrderID string `json:"orderId"` ShippingDetails *ShippingDetails `json:"shippingDetails"` TransactionInfo *TransactionInfo `json:"transactionInfo"` UserDetails *UserDetails `json:"userDetails"` ErrorInfo *EcomAPIError `json:"errorInfo"` }
TransactionUpdate represents a transaction update from Vipps
type UserDetails ¶
type UserDetails struct { BankIDVerified string `json:"bankIdVerified,omitempty"` DateOfBirth string `json:"dateOfBirth,omitempty"` Email string `json:"email,omitempty"` FirstName string `json:"firstName,omitempty"` LastName string `json:"lastName,omitempty"` MobileNumber string `json:"mobileNumber,omitempty"` SSN string `json:"ssn,omitempty"` UserID string `json:"userId,omitempty"` }
UserDetails represents customer details from Vipps