AuthorizeCIM

package module
v0.0.0-...-37aeafd Latest Latest
Warning

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

Go to latest
Published: May 9, 2017 License: MIT Imports: 5 Imported by: 2

README

alt tag

Authorize.net CIM for golang

Build Status Code Climate Coverage Status GoDoc

Give your Go Language applications the ability to store and retrieve credit cards from Authorize.net CIM API.

Usage

  • Import package
go get github.com/avator/authorizecim
import "github.com/avator/authorizecim"
  • Set Authorize.net API Keys
// Set your Authorize API name and key here
// You can get Sandbox Access at:  https://developer.authorize.net/hello_world/sandbox/
apiName := "auth_name_here"
apiKey := "auth_transaction_key_here"
AuthorizeCIM.SetAPIInfo(apiName,apiKey,"test")
// use "live" to do transactions on production server

Features

  • Creating Users Accounts based on user's unique ID and/or email address
  • Store Billing Profiles (credit card) on Authorize.net using Customer Information Manager (CIM)
  • Create Subscriptions (monthly, weekly, days) with Automated Recurring Billing (ARB)
  • Fetch customers billing profiles in a simple["array"]
  • Process transactions using customers stored credit card
  • Delete and Updating billing profiles
  • Add Shipping Profiles into user accounts
  • Delete a customers entire account

alt tag

Examples

Below you'll find useful functions to get you up and running in no time!

Test Correct API Key
connected := AuthorizeCIM.TestConnection()
// true or false
Create new Customer Account
customer_info := AuthorizeCIM.AuthUser{
                  "54",
                  "email@domain.com",
                  "Test Account",
                  }
new_customer, success := AuthorizeCIM.CreateCustomerProfile(customer_info)
// outputs new user profile ID, and true/false
Create Payment Profile for Customer
address := AuthorizeCIM.Address{
                  FirstName: "Test", 
                  LastName: "User", 
                  Address: "1234 Road St", 
                  City: "City Name", 
                  State:" California",
                  Zip: "93063", 
                  Country: "USA", 
                  PhoneNumber: "5555555555",
                  }
credit_card := AuthorizeCIM.CreditCard{
                  CardNumber: "4111111111111111", 
                  ExpirationDate: "2020-12",
                  }
profile_id := "53"
newPaymentID, success := AuthorizeCIM.CreateCustomerBillingProfile(profile_id, credit_card, address)
// outputs new payment profile ID and true/false
Get Customers stored billing accounts
profile_id := "30089822"
profile, success := AuthorizeCIM.GetCustomerProfile(profile_id)
// outputs array of user payment account, and true/false
Delete Customer Profile
profile_id := "30089822"
success = AuthorizeCIM.DeleteCustomerProfile(profile_id)
// outputs true or false
Get detailed information about the Billing Profile from customer
profile_id := "30089822"
payment_id := "1200079812"
stored_card, success := AuthorizeCIM.GetCustomerPaymentProfile(profile_id,payment_id)
// outputs payment profiles, and true/false
Delete customers Billing Profile
profile_id := "30089822"
payment_id := "1200079812"
success := AuthorizeCIM.DeleteCustomerPaymentProfile(profile_id,payment_id)
// outputs true or false
Update a single Billing Profile with new information
new_address := AuthorizeCIM.Address{
                  FirstName: "Test", 
                  LastName: "User", 
                  Address: "1234 Road St", 
                  City: "City Name", 
                  State:" California",
                  Zip: "93063", 
                  Country: "USA", 
                  PhoneNumber: "5555555555"
                  }
credit_card := AuthorizeCIM.CreditCard{
                  CardNumber: "4111111111111111", 
                  ExpirationDate: "2020-12"
                  }
profile_id := "53"
payment_id := "416"
success := AuthorizeCIM.UpdateCustomerPaymentProfile(profile_id,payment_id,new_address,credit_card)
// outputs true or false
Create a Transaction that will be charged on Customers Billing Profile
item := AuthorizeCIM.LineItem{
                  ItemID: "S0897", 
                  Name: "New Product", 
                  Description: "brand new", 
                  Quantity: "1", 
                  UnitPrice: "14.43",
                  }
amount := "14.43"
profile_id := "53"
payment_id := "416"

response, approved, success := AuthorizeCIM.CreateTransaction(profile_id, payment_id, item, amount)
// outputs transaction response, approved status (true/false), and success status (true/false)

var tranxID string
if success {
		tranxID = response["transId"].(string)
		if approved {
			fmt.Println("Transaction was approved! "+tranxID+"\n")
		} else {
			fmt.Println("Transaction was denied! "+tranxID+"\n")
		}
	} else {
		fmt.Println("Transaction has failed! \n")
	}
Create a Subscription
startTime := time.Now().Format("2006-01-02")
totalRuns := "9999" //means forever
trialRuns := "0"
profile_id := "53"
payment_id := "416"
shipping_id := "9503"

userFullProfile := FullProfile{CustomerProfileID: profile_id,CustomerAddressID: shipping_id, CustomerPaymentProfileID: payment_id}

paymentSchedule := PaymentSchedule{
                        Interval: Interval{"1","months"}, 
                        StartDate:startTime, 
                        TotalOccurrences:totalRuns, 
                        TrialOccurrences:trialRuns}
                        
subscriptionInput := Subscription{"Advanced Subscription",paymentSchedule,"7.98","0.00",userFullProfile}

newSubscription, success := CreateSubscription(subscriptionInput)
	if success {
		fmt.Println("User created a new Subscription id: "+newSubscription+"\n")
	} else {
		fmt.Println("created the subscription failed, the user might not be fully inputed yet. \n")
	}
Some transactions or subscriptions may not process if you do many functions in a short amount of time.

Testing

Include "apiName" and "apiKey" as environment variables
go test -v 
//apiName = os.Getenv("apiName")
//apiKey = os.Getenv("apiKey")
This will run a test of each function, make sure you have correct API keys for Authorize.net

alt tag

ToDo

  • Make cleaner maps for outputs
  • Functions to search Subscriptions (active, expired, etc)
  • Void and Refund Transactions
  • Add Bank Account Support
  • Authorize Only methods
Authorize.net CIM Documentation

http://developer.authorize.net/api/reference/#customer-profiles

Authorize.net Sandbox Access

https://developer.authorize.net/hello_world/sandbox/

License

This golang package is release under MIT license. This software gets reponses in JSON, but Authorize.net currently says "JSON Support is in BETA, please contact us if you intend to use it in production." Make sure you test in sandbox mode!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthorizeCard

func AuthorizeCard(creditCard CreditCardCVV, amount string) (map[string]interface{}, bool, bool)

func CreateCustomerBillingProfile

func CreateCustomerBillingProfile(profileID string, creditCard CreditCard, address Address) (string, map[string]interface{}, bool)

func CreateCustomerProfile

func CreateCustomerProfile(userInfo AuthUser) (string, map[string]interface{}, bool)

func CreateShippingAddress

func CreateShippingAddress(profileID string, address Address) (string, bool)

func CreateSubscription

func CreateSubscription(newSubscription Subscription) (string, bool)

func CreateTransaction

func CreateTransaction(profileID string, paymentID string, item LineItem, amount string) (map[string]interface{}, bool, bool)

func DeleteCustomerPaymentProfile

func DeleteCustomerPaymentProfile(profileID string, paymentID string) bool

func DeleteCustomerProfile

func DeleteCustomerProfile(profileID string) bool

func DeleteShippingAddress

func DeleteShippingAddress(profileID string, shippingID string) bool

func DeleteSubscription

func DeleteSubscription(subscriptionId string) bool

func FindResultCode

func FindResultCode(incoming map[string]interface{}) bool

func GetAllProfiles

func GetAllProfiles() []interface{}

func GetCustomerPaymentProfile

func GetCustomerPaymentProfile(profileID string, paymentID string) (map[string]interface{}, bool)

func GetCustomerProfile

func GetCustomerProfile(profileID string) (map[string]interface{}, bool)

func GetShippingAddress

func GetShippingAddress(profileID string, shippingID string) (map[string]interface{}, bool)

func GetSubscriptions

func GetSubscriptions()

func GetTransactionDetails

func GetTransactionDetails(tranID string) map[string]interface{}

func RefundTransaction

func RefundTransaction(transactionId string, amount string, creditCardLastFour string, cardExp string) (map[string]interface{}, bool, bool)

func SendRequest

func SendRequest(input string) (map[string]interface{}, interface{})

func SetAPIInfo

func SetAPIInfo(name string, key string, mode string)

func TestConnection

func TestConnection() bool

func TransactionApproved

func TransactionApproved(incoming map[string]interface{}) bool

func UpdateCustomerPaymentProfile

func UpdateCustomerPaymentProfile(profileID string, paymentID string, creditCard CreditCard, address Address) bool

func UpdateSubscription

func UpdateSubscription()

func VoidTransaction

func VoidTransaction(transactionId string) bool

Types

type ARBCreateSubscription

type ARBCreateSubscription struct {
	MerchantAuthentication MerchantAuthentication `json:"merchantAuthentication"`
	Subscription           Subscription           `json:"subscription"`
}

type Address

type Address struct {
	FirstName   string `json:"firstName"`
	LastName    string `json:"lastName"`
	Address     string `json:"address"`
	City        string `json:"city"`
	State       string `json:"state"`
	Zip         string `json:"zip"`
	Country     string `json:"country"`
	PhoneNumber string `json:"phoneNumber"`
}

type AllCustomerProfileIds

type AllCustomerProfileIds struct {
	CustomerProfileIdsRequest getCustomerProfileIdsRequest `json:"getCustomerProfileIdsRequest"`
}

type AuthUser

type AuthUser struct {
	Uuid        string
	Email       string
	Description string
}

type AuthenticateTestRequest

type AuthenticateTestRequest struct {
	MerchantAuthentication MerchantAuthentication `json:"merchantAuthentication"`
}

type AuthorizeNetTest

type AuthorizeNetTest struct {
	AuthenticateTestRequest AuthenticateTestRequest `json:"authenticateTestRequest"`
}

type AuthorizeTransactionRequest

type AuthorizeTransactionRequest struct {
	TransactionType string     `json:"transactionType"`
	Amount          string     `json:"amount"`
	Payment         PaymentCVV `json:"payment"`
}

type AuthorizeTransactionRequestARB

type AuthorizeTransactionRequestARB struct {
	AuthorizeTransaction CreateAuthorizeTransactionRequest `json:"createTransactionRequest"`
}

type BillTo

type BillTo struct {
	Address Address `json:"billTo"`
}

type BillingProfile

type BillingProfile struct {
	Address        Address               `json:"billTo"`
	PaymentProfile PaymentBillingProfile `json:"paymentProfile"`
}

type CreateAuthorizeTransactionRequest

type CreateAuthorizeTransactionRequest struct {
	MerchantAuthentication MerchantAuthentication      `json:"merchantAuthentication"`
	RefID                  string                      `json:"refId"`
	AuthorizeTranx         AuthorizeTransactionRequest `json:"transactionRequest"`
}

type CreateCustomerBillingProfileRequest

type CreateCustomerBillingProfileRequest struct {
	MerchantAuthentication MerchantAuthentication `json:"merchantAuthentication"`
	CustomerProfileId      string                 `json:"customerProfileId"`
	Profile                PaymentBillingProfile  `json:"paymentProfile"`
	ValidationMode         string                 `json:"validationMode"`
}

type CreateCustomerProfileRequest

type CreateCustomerProfileRequest struct {
	MerchantAuthentication MerchantAuthentication `json:"merchantAuthentication"`
	Profile                Profile                `json:"profile"`
}

type CreateRefundTransactionRequest

type CreateRefundTransactionRequest struct {
	MerchantAuthentication   MerchantAuthentication   `json:"merchantAuthentication"`
	RefundTransactionRequest RefundTransactionRequest `json:"transactionRequest"`
}

type CreateSubscriptionRequest

type CreateSubscriptionRequest struct {
	CreateSubscription ARBCreateSubscription `json:"ARBCreateSubscriptionRequest"`
}

type CreateTransactionRequest

type CreateTransactionRequest struct {
	MerchantAuthentication MerchantAuthentication `json:"merchantAuthentication"`
	RefID                  string                 `json:"refId"`
	TransactionRequest     TransactionRequest     `json:"transactionRequest"`
}

type CreditCard

type CreditCard struct {
	CardNumber     string `json:"cardNumber"`
	ExpirationDate string `json:"expirationDate"`
}

type CreditCardCVV

type CreditCardCVV struct {
	CardNumber     string `json:"cardNumber"`
	ExpirationDate string `json:"expirationDate"`
	CardCode       string `json:"cardCode"`
}

type CustomerPaymentProfileRequest

type CustomerPaymentProfileRequest struct {
	MerchantAuthentication   MerchantAuthentication `json:"merchantAuthentication"`
	CustomerProfileId        string                 `json:"customerProfileId"`
	CustomerPaymentProfileId string                 `json:"customerPaymentProfileId"`
}

type CustomerProfile

type CustomerProfile struct {
	CustomerProfileRequest getCustomerProfileRequest `json:"getCustomerProfileRequest"`
}

type CustomerShippingAddress

type CustomerShippingAddress struct {
	MerchantAuthentication MerchantAuthentication `json:"merchantAuthentication"`
	CustomerProfileId      string                 `json:"customerProfileId"`
	Address                Address                `json:"address"`
}

type CustomerShippingAddressRequest

type CustomerShippingAddressRequest struct {
	CustomerShippingAddress CustomerShippingAddress `json:"createCustomerShippingAddressRequest"`
}

type DeleteARBSubscriptionRequest

type DeleteARBSubscriptionRequest struct {
	ARBCancelSubscriptionRequest DeleteSubscriptionRequest `json:"ARBCancelSubscriptionRequest"`
}

type DeleteCustomerShippingAddressRequest

type DeleteCustomerShippingAddressRequest struct {
	GetCustomerShippingAddress GetCustomerShippingAddress `json:"deleteCustomerShippingAddressRequest"`
}

type DeleteSubscriptionRequest

type DeleteSubscriptionRequest struct {
	MerchantAuthentication MerchantAuthentication `json:"merchantAuthentication"`
	SubscriptionId         string                 `json:"subscriptionId"`
}

type DoCreateTransaction

type DoCreateTransaction struct {
	CreateTransactionRequest CreateTransactionRequest `json:"createTransactionRequest"`
}

type DoRefundTransaction

type DoRefundTransaction struct {
	CreateRefundTransactionRequest CreateRefundTransactionRequest `json:"createTransactionRequest"`
}

type FullProfile

type FullProfile struct {
	CustomerProfileID        string `json:"customerProfileId"`
	CustomerPaymentProfileID string `json:"customerPaymentProfileId"`
	CustomerAddressID        string `json:"customerAddressId"`
}

type GetCustomerShippingAddress

type GetCustomerShippingAddress struct {
	MerchantAuthentication MerchantAuthentication `json:"merchantAuthentication"`
	CustomerProfileId      string                 `json:"customerProfileId"`
	CustomerShippingId     string                 `json:"customerAddressId"`
}

type GetCustomerShippingAddressRequest

type GetCustomerShippingAddressRequest struct {
	GetCustomerShippingAddress GetCustomerShippingAddress `json:"getCustomerShippingAddressRequest"`
}

type Interval

type Interval struct {
	Length string `json:"length"`
	Unit   string `json:"unit"`
}

type LineItem

type LineItem struct {
	ItemID      string `json:"itemId"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Quantity    string `json:"quantity"`
	UnitPrice   string `json:"unitPrice"`
}

type LineItems

type LineItems struct {
	LineItem LineItem `json:"lineItem"`
}

type MerchantAuthentication

type MerchantAuthentication struct {
	Name           string `json:"name"`
	TransactionKey string `json:"transactionKey"`
}

type MinTrans

type MinTrans struct {
	TransactionType string `json:"transactionType"`
	TransxId        string `json:"refTransId"`
}

type NewCustomerBillingProfile

type NewCustomerBillingProfile struct {
	CreateCustomerProfileRequest CreateCustomerBillingProfileRequest `json:"createCustomerPaymentProfileRequest"`
}

type NewCustomerProfile

type NewCustomerProfile struct {
	CreateCustomerProfileRequest CreateCustomerProfileRequest `json:"createCustomerProfileRequest"`
}

type Payment

type Payment struct {
	CreditCard CreditCard `json:"creditCard"`
}

type PaymentBillingProfile

type PaymentBillingProfile struct {
	Address Address `json:"billTo"`
	Payment Payment `json:"payment"`
}

type PaymentCVV

type PaymentCVV struct {
	CreditCard CreditCardCVV `json:"creditCard"`
}

type PaymentProfiles

type PaymentProfiles struct {
	CustomerType string  `json:"customerType"`
	Payment      Payment `json:"payment"`
}

type PaymentSchedule

type PaymentSchedule struct {
	Interval         Interval `json:"interval"`
	StartDate        string   `json:"startDate"`
	TotalOccurrences string   `json:"totalOccurrences"`
	TrialOccurrences string   `json:"trialOccurrences"`
}

type Profile

type Profile struct {
	MerchantCustomerID string `json:"merchantCustomerId"`
	Description        string `json:"description"`
	Email              string `json:"email"`
}

type RefundTransactionRequest

type RefundTransactionRequest struct {
	TransactionType string  `json:"transactionType"`
	Amount          string  `json:"amount"`
	Payment         Payment `json:"payment"`
	TransxId        string  `json:"refTransId"`
}

type SubProfile

type SubProfile struct {
	CustomerPaymentProfileId string `json:"paymentProfileId"`
}

type Subscription

type Subscription struct {
	Name            string          `json:"name"`
	PaymentSchedule PaymentSchedule `json:"paymentSchedule"`
	Amount          string          `json:"amount"`
	TrialAmount     string          `json:"trialAmount"`
	FullProfile     FullProfile     `json:"profile"`
}

type TranProfile

type TranProfile struct {
	CustomerProfileId string     `json:"customerProfileId"`
	SubProfile        SubProfile `json:"paymentProfile"`
}

type TransactionDetails

type TransactionDetails struct {
	MerchantAuthentication MerchantAuthentication `json:"merchantAuthentication"`
	TransId                string                 `json:"transId"`
}

type TransactionDetailsRequest

type TransactionDetailsRequest struct {
	TransactionDetails TransactionDetails `json:"getTransactionDetailsRequest"`
}

type TransactionMessages

type TransactionMessages struct {
}

type TransactionRecord

type TransactionRecord struct {
}

type TransactionRequest

type TransactionRequest struct {
	TransactionType string      `json:"transactionType"`
	Amount          string      `json:"amount"`
	TranProfile     TranProfile `json:"profile"`
	LineItems       LineItems   `json:"lineItems"`
}

type TransactionResponse

type TransactionResponse struct {
	ResponseCode   string `json:"responseCode"`
	AuthCode       string `json:"authCode"`
	AvsResultCode  string `json:"avsResultCode"`
	CvvResultCode  string `json:"cvvResultCode"`
	CavvResultCode string `json:"cavvResultCode"`
	TransID        string `json:"transId"`
	RefTransID     string `json:"refTransID"`
	TransHash      string `json:"transHash"`
	TestRequest    string `json:"testRequest"`
	AccountNumber  string `json:"accountNumber"`
	AccountType    string `json:"accountType"`
}

type UpdatePaymentBillingProfile

type UpdatePaymentBillingProfile struct {
	Address                  Address `json:"billTo"`
	Payment                  Payment `json:"payment"`
	CustomerPaymentProfileId string  `json:"customerPaymentProfileId"`
}

type User

type User struct {
	ID               string
	Email            string
	ProfileID        string
	BillingProfiles  interface{}
	ShippingProfiles interface{}
	Subscriptions    map[string]interface{}
}
var CurrentUser User

func MakeUser

func MakeUser(userID string) User

type VoidTransactionRequest

type VoidTransactionRequest struct {
	MerchantAuthentication MerchantAuthentication `json:"merchantAuthentication"`
	MinTrans               MinTrans               `json:"transactionRequest"`
}

type VoidTransactionRequestARB

type VoidTransactionRequestARB struct {
	VoidTransaction VoidTransactionRequest `json:"createTransactionRequest"`
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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