komoju

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

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

Go to latest
Published: Jun 21, 2019 License: MIT Imports: 10 Imported by: 0

README

GoDoc Go report card GolangCI Build Status codecov CircleCI

komoju-go

Unoffical Golang wrapper for Komoju api. Based on documentation available here: https://docs.komoju.com/en/getting_started/overview/#products

A work-in-progress written mostly for fun. Any bugs found please feel free to open an issue and/or raise a PR.

Usage
Hosted Page
package main

import (
	komoju "github.com/galaco/komoju-go"
)

func main() {
	locale := "en"
	merchantUuid := "degica-mart"
	paymentMethod := komoju.PaymentMethodCreditCard
	baseUri := komoju.HostedPageBaseURI(locale, merchantUuid, paymentMethod)
	
	// your secret key
	secretKey := []byte("ABCD1234567890")
	config := komoju.HostedPageConfig{
    	Transaction: komoju.HostedPageTransaction{
    		Amount: 130,
    		Currency: "JPY",
    		Customer: komoju.HostedPageCustomer{
    			GivenName: "John",
    			FamilyName: "Smith",
    			GivenNameKana: "John",
    			FamilyNameKana: "Smith",
    			Email: "",
    			Phone: "",
    		},
    		ExternalOrderNumber: "M8x6U6Z5HEeXv3",
    		ReturnUrl: "http://example.com/?sucess=true",
    		CancelUrl: "http://example.com/?cancel=true",
    		Tax: 0,
    	},
        Timestamp: 1561022519,
    }
	
	paymentUri,_ := komoju.HostedPageURI(secretKey, baseUri, &config)
	// Now redirect to paymentUri
}
API
package main

import (
	komoju "github.com/galaco/komoju-go"
	"log"
)	
func main() {
    // ... make a request to the komoju API
    // expect a standard response.Body as io.ReadCloser

    payload := komoju.ApiResponseEvents{}
    // remember to handle error
    _ := komoju.ParseApiResponse(response.Body, &payload)
    
    // Do whatever with response
    log.Println(payload.Data[0].Resource)
}

Documentation

Index

Constants

View Source
const (
	// PaymentMethodBankTransfer is bank transfer payment method
	PaymentMethodBankTransfer = PaymentMethod("bank_transfer")
	// PaymentMethodBitCash is BitCash payment method
	PaymentMethodBitCash = PaymentMethod("bit_cash")
	// PaymentMethodCreditCard is Credit Card payment method
	PaymentMethodCreditCard = PaymentMethod("credit_card")
	// PaymentMethodKonbini is Konbini payment method
	PaymentMethodKonbini = PaymentMethod("konbini")
	// PaymentMethodNanaco is Nanaco payment method
	PaymentMethodNanaco = PaymentMethod("nanaco")
	// PaymentMethodNetCash is Net Cash payment method
	PaymentMethodNetCash = PaymentMethod("net_cash")
	// PaymentMethodPayEasy is Pay Easy payment method
	PaymentMethodPayEasy = PaymentMethod("pay_easy")
	// PaymentMethodWebMoney is Web Money payment method
	PaymentMethodWebMoney = PaymentMethod("web_money")
)

Variables

This section is empty.

Functions

func HostedPageBaseURI

func HostedPageBaseURI(locale, merchantUuid string, paymentMethod PaymentMethod) string

HostPageBaseURI create the base URI for Komoju Hosted page api request

func HostedPageURI

func HostedPageURI(secretKey []byte, baseURI string, config *HostedPageConfig) (string, error)

HostedPageURI returns the URI for a hosted page

func ParseApiResponse

func ParseApiResponse(payload io.ReadCloser, resp interface{}) (err error)

ParseApiResponse

Types

type ApiResponseCustomer

type ApiResponseCustomer struct {
	// id
	Id string `json:"id"`
	// Resource
	Resource string `json:"resource"`
	// Email
	Email string `json:"email"`
	// Source
	Source string `json:"source"`
	// Metadata
	Metadata map[string]string `json:"metadata"`
	// CreatedAt
	CreatedAt string `json:"created_at"`
}

ApiResponseCustomer maps to response body of single customer

type ApiResponseCustomers

type ApiResponseCustomers struct {
	ApiResponseList
	// Data
	Data []ApiResponseCustomer `json:"data"`
}

ApiResponseCustomers maps to response body of customer list

type ApiResponseError

type ApiResponseError struct {
	// Data
	Data ApiResponseErrorMessage `json:"error"`
}

ApiResponseError maps to a response error body

func NewApiResponseError

func NewApiResponseError(code, param, message string) *ApiResponseError

NewApiResponseError creates a new response error

func (ApiResponseError) Error

func (err ApiResponseError) Error() string

Error returns the error in a simplfied manner

type ApiResponseErrorMessage

type ApiResponseErrorMessage struct {
	Message string `json:"message"`
	Code    string `json:"code"`
	Param   string `json:"param"`
}

ApiResponseErrorMessage

type ApiResponseEvent

type ApiResponseEvent struct {
	// Id
	Id string `json:"id"`
	// Type
	Type string `json:"type"`
	// Resource
	Resource string `json:"resource"`
	// Data
	Data ApiResponsePaymentDetail `json:"data"`
	// CreatedAt
	CreatedAt string `json:"created_at"`
}

ApiResponseEvent maps to a response for a single event

type ApiResponseEvents

type ApiResponseEvents struct {
	ApiResponseList
	Data []ApiResponseEvent `json:"data"`
}

Events ApiResponseEvents maps to a response to list events

type ApiResponseList

type ApiResponseList struct {
	// Resource
	Resource string `json:"list"`
	// Total
	Total int64 `json:"total"`
	// Page
	Page int64 `json:"page"`
	// PerPage
	PerPage int64 `json:"per_page"`
	// lastPage
	LastPage int64 `json:"last_page"`
}

ApiResponseList provides properties across all api response body lists

type ApiResponsePayment

type ApiResponsePayment struct {
	// Id
	Id string `json:"id"`
	// Resource
	Resource string `json:"resource"`
	// Status
	Status string `json:"status"`
	// Amount
	Amount float64 `json:"amount"`
	// Tax
	Tax float64 `json:"tax"`
	// Customer
	Customer ApiResponseCustomer `json:"customer"`
	// PaymentDeadline
	PaymentDeadline string `json:"payment_deadline"`
	// PaymentDetails
	PaymentDetails ApiResponsePaymentDetail `json:"payment_details"`
	// PaymentMethodFee
	PaymentMethodFee float64 `json:"payment_method_fee"`
	// Total
	Total float64 `json:"total"`
	// Currency
	Currency string `json:"currency"`
	// Description
	Description string `json:"description"`
	// CapturedAt
	CapturedAt string `json:"captured_at"`
	// ExternalOrderNumber
	ExternalOrderNumber string `json:"external_order_num"`
	// Metadata
	MetaData map[string]string `json:"metadata"`
	// CreatedAt
	CreatedAt string `json:"created_at"`
	// AmountRefunded
	AmountRefunded float64 `json:"amount_refunded"`
	// Locale
	Locale string `json:"locale"`
	// Refunds
	Refunds []ApiResponseRefund `json:"refunds"`
	// RefundRequests
	RefundRequests []string `json:"refund_requests"`
}

ApiResponsePayment maps to a response for a single payment

type ApiResponsePaymentDetail

type ApiResponsePaymentDetail struct {
	// Type
	Type PaymentMethod `json:"type"`
	// Email
	Email string `json:"email"`
	// GivenName
	GivenName string `json:"given_name"`
	// FamilyName
	FamilyName string `json:"family_name"`
	// GivenNamek\Kana
	GivenNameKana string `json:"given_name_kana"`
	// FamilyNameKana
	FamilyNameKana string `json:"family_name_kana"`
	// Phone
	Phone string `json:"phone"`

	// Credit card
	// Brand
	Brand string `json:"brand"`
	// last4Digits
	Last4Digits string `json:"last_four_digits"`
	// Month
	Month int64 `json:"month"`
	// Year
	Year int64 `json:"year"`

	// Konbini
	// Store
	Store string `json:"store"`
	// ConfirmationCode
	ConfirmationCode string `json:"confirmation_code"`
	// Receipt
	Receipt string `json:"receipt"`
	// InstructionsUrl
	InstructionsUrl string `json:"instructions_url"`

	// Bank transfer
	// orderId
	OrderId string `json:"order_id"`
	// BankName
	BankName string `json:"bank_name"`
	// AccountBranchName
	AccountBranchName string `json:"account_branch_name"`
	// AccountNumber
	AccountNumber string `json:"account_number"`
	// AccountType
	AccountType string `json:"account_type"`
	// AccountName
	AccountName string `json:"account_name"`

	// PayEasy
	// BankId
	BankId string `json:"bank_id"`
	// CustomerId
	CustomerId string `json:"customer_id"`
	// ConfirmationId
	ConfirmationId string `json:"confirmation_id"`

	// WebMoney/Bitcash/Nanaco/Net Cash
	// ShortAmount
	ShortAmount float64 `json:"short_amount"`
	// PrepaidCards
	PrepaidCards []ApiResponsePaymentPrepaidCard `json:"prepaid_cards"`
}

ApiResponsePaymentDetail maps to a response for a Payment

type ApiResponsePaymentPrepaidCard

type ApiResponsePaymentPrepaidCard struct {
	// Last4Digits
	Last4Digits string `json:"last_four_digits"`
	// Points
	Points int64 `json:"points"`
}

ApiResponsePaymentPrepaidCard maps to prepaid card properties on payment details

type ApiResponsePayments

type ApiResponsePayments struct {
	ApiResponseList
	// Data
	Data []ApiResponsePayment `json:"data"`
}

Payment ApiResponsePayments maps to a response for a list of payments

type ApiResponseRefund

type ApiResponseRefund struct {
	// id
	Id string `json:"id"`
	// Resource
	Resource string `json:"resource"`
	// Amount
	Amount float64 `json:"amount"`
	// Currency
	Currency string `json:"currency"`
	// Payment
	Payment string `json:"payment"`
	// Description
	Description string `json:"description"`
	// CreatedAt
	CreatedAt string `json:"created_at"`
	// Chargeback
	Chargeback string `json:"chargeback"`
}

ApiResponseRefund maps to refund property on payment details

type HostedPageConfig

type HostedPageConfig struct {
	// Transaction contains information about the order
	Transaction HostedPageTransaction `url:"transaction"`
	// Timestamp should be the current time
	Timestamp int64 `url:"timestamp"`
}

HostedPageConfig provides a struct that holds all parameters that can be passed to the HostedPage API

type HostedPageCustomer

type HostedPageCustomer struct {
	// GivenName is given/first name
	GivenName string `url:"given_name"`
	// FamilyName is family/last name
	FamilyName string `url:"family_name"`
	// GivenNameKana is given/first name represented as Kana
	GivenNameKana string `url:"given_name_kana"`
	// FamilyNameKana is family/last name represented as Kana
	FamilyNameKana string `url:"family_name_kana"`
	// Email is the cutomers email address
	Email string `url:"email"`
	// Phone is the customers phone number
	Phone string `url:"phone"`
}

HostedPageCustimer contains customer information, used to pre-fill the Hosted Page form

type HostedPageTransaction

type HostedPageTransaction struct {
	// Amount is how much this transaction is for
	Amount float64 `url:"amount"`
	// Currency is the currency this transaction will use
	Currency string `url:"currency"`
	// Customer provides customer personal information
	Customer HostedPageCustomer `url:"customer"`
	// ExternalOrderNumber is a unique order id
	ExternalOrderNumber string `url:"external_order_num"`
	// ReturnUrl provides a URL to redirect after completion
	ReturnUrl string `url:"return_url"`
	// cancelUrl provides a return URL for transaction cancellation
	CancelUrl string `url:"cancel_url"`
	// Tax is the amount applied for tax
	Tax float32 `url:"tax"`
	// Metadata is optional.
	Metadata map[string]string `url:"metadata"`
}

HostedPageTransaction contains transaction information for the hosted page

type PaymentMethod

type PaymentMethod string

PaymentMethod is an alias to String type to restrict to valid payment options

Jump to

Keyboard shortcuts

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