Go Language
Go Language

Authorize.net Subscription with Go Language



Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /usr/www/phpsites/public/yayprogramming/wp-content/plugins/wp-syntax/wp-syntax.php on line 383

Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /usr/www/phpsites/public/yayprogramming/wp-content/plugins/wp-syntax/wp-syntax.php on line 383

Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /usr/www/phpsites/public/yayprogramming/wp-content/plugins/wp-syntax/wp-syntax.php on line 383

Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /usr/www/phpsites/public/yayprogramming/wp-content/plugins/wp-syntax/wp-syntax.php on line 383

Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /usr/www/phpsites/public/yayprogramming/wp-content/plugins/wp-syntax/wp-syntax.php on line 383

Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /usr/www/phpsites/public/yayprogramming/wp-content/plugins/wp-syntax/wp-syntax.php on line 383

Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /usr/www/phpsites/public/yayprogramming/wp-content/plugins/wp-syntax/wp-syntax.php on line 383

In this post you’ll see how to use AuthorizeCIM to create a subscription with the payment gateway Authorize.net. This Golang package is tested on Travis.org.

For this package a sandbox account is required. Get a Authorize.net Sandbox Account

1
go get github.com/hunterlong/authorizecim
1
import "github.com/hunterlong/authorizecim"

In main()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
// import "github.com/hunterlong/authorizecim"
 
func main() {
 
apiName = "auth_name_here"
apiKey = "auth_transaction_key_here"
authMode := "test"
 
AuthorizeCIM.SetAPIInfo(apiName,apiKey,authMode)
 
connected := AuthorizeCIM.TestConnection()
fmt.Println("Authorize has correct API Keys:, connected);
 
}

For a Brand New User (without a Profile ID from Auth)

1
2
3
4
5
6
7
8
customer_info := AuthorizeCIM.AuthUser{
                  "42",
                  "email@domain.com",
                  "Test Account",
                  }
profile_id, success := AuthorizeCIM.CreateCustomerProfile(customer_info)
 
// profile_id is the profile ID for authorize.net (save in db for user)

Or get the current User Profile ID from Authorize.net
This value should be stored in the database for user. Authorize.net does not allow multiple profile’s with the same email address.

1
profile_id := "5894983"

Create Shipping and Payment Profile with Credit Card
newPaymentID and newShippingID shouldn’t be stored in your database. You can fetch these by using AuthorizeCIM.
List of Authorize.net Test Credit Cards

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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",
                  }
 
newPaymentID, success := AuthorizeCIM.CreateCustomerBillingProfile(profile_id, credit_card, address)
 
newShippingID, success := AuthorizeCIM.CreateShippingAddress(profile_id, address)

Create Subscription
This will create a subscription called “Advanced Subscription” for $7.98 every month. In this subscription, there is no trial period. To make a trial subscription, change trialRuns to the amount of increments (based off of the PaymentSchedule). If you want a trial price to be charged, change trialAmount.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
startTime := time.Now().Format("2006-01-02")
totalCost := "7.98"
totalRuns := "9999" //means forever
trialRuns := "0"
trialAmount := "5.00"
 
userFullProfile := AuthorizeCIM.FullProfile{CustomerProfileID: profile_id,CustomerAddressID: newShippingID, CustomerPaymentProfileID: newPaymentID}
 
paymentSchedule := AuthorizeCIM.PaymentSchedule{
                        Interval: Interval{"1","months"}, 
                        StartDate:startTime, 
                        TotalOccurrences:totalRuns, 
                        TrialOccurrences:trialRuns,
                   }
 
// Insert your subscription Title, Charge amount, Trial amount
subscriptionInput := AuthorizeCIM.Subscription{"Advanced Subscription",paymentSchedule,totalCost,trialAmount,userFullProfile}
 
newSubscription, success := AuthorizeCIM.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")
    }

You should now have a subscription ID from Authorize.net. You can use the subscription ID and the user’s profile ID to get more information about the user and their subscriptions.


View Comments
There are currently no comments.