Categorygithub.com/splitit/splitit.sdks.go
repositorypackage
1.6.10
Repository: https://github.com/splitit/splitit.sdks.go.git
Documentation: pkg.go.dev

# README

Splitit SDK for Go language

This is Splitit Web API SDK source code for Go applications. For other languages, please visit Splitit.SDKs.

Overview

  • API version: 1.0.0
  • Package version: 1.6.10

Installation

Install the following dependencies:

go get github.com/stretchr/testify/assert
go get golang.org/x/oauth2
go get github.com/fatih/structs
go get golang.org/x/net/context
go get github.com/antihax/optional
go get github.com/btubbs/datetime

Install the Splitit SDK package:

go get github.com/splitit/splitit.sdks.go

Getting Started

Replace YOUR_API_KEY, YOUR_USERNAME and YOUR_PASSWORD placeholders with your corresponding credentials. Please install required packages as described above and then run the following:

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/splitit/splitit.sdks.go"
)

func main() {
	// Recommended to have one shared client
	// Use splitit.NewSandboxAPIClient for development and splitit.NewAPIClient in production
	client := splitit.NewSandboxAPIClient(
		"_YOUR_API_KEY_",
		"_YOUR_USERNAME_",
		"_YOUR_PASSWORD_",
		// Supply optional configuration
		// splitit.Debug(), // print out full request and response
		splitit.DefaultCulture("en-US"),
	)

	ctx := context.TODO()

	// Create initiate request
	initReq := splitit.InitiateInstallmentPlanRequest{
		PlanData: &splitit.PlanData{
			Amount: &splitit.MoneyWithCurrencyCode{300, "USD"},
			NumberOfInstallments: 3,
		},
		BillingAddress: &splitit.AddressData{
			AddressLine:  "260 Madison Avenue.",
			AddressLine2: "Apartment 1",
			City:         "New York",
			State:        "NY",
			Country:      "USA",
			Zip:          "10016",
		},
		ConsumerData: &splitit.ConsumerData{
			FullName:    "John Smith",
			Email:       "[email protected]",
			PhoneNumber: "1-415-775-4848",
			CultureName: "en-us",
		},
	}

	initResponse, _, err := client.InstallmentPlanApi.InstallmentPlanInitiate(
		// DefaultCulture could be overridden on per-request basis:
		splitit.WithCulture(ctx, "en-GB"),
		initReq,
	)

	if err != nil {
		fmt.Printf("Error during initiate: %s\n", err)
		os.Exit(1)
	} else {
		fmt.Printf("Initiate success: %t\n", initResponse.ResponseHeader.Succeeded)
	}

	createReq := splitit.CreateInstallmentPlanRequest{
		CreditCardDetails: &splitit.CardData{
			CardNumber:         "411111111111111",
			CardCvv:            "111",
			CardHolderFullName: "John Smith",
			CardExpMonth:       "12",
			CardExpYear:        "2022",
		},
		InstallmentPlanNumber: initResponse.InstallmentPlan.InstallmentPlanNumber,
	}

	createResponse, _, err := client.InstallmentPlanApi.InstallmentPlanCreate(ctx, createReq)

	if err != nil {
		fmt.Printf("Create error: %s\n", err)
	} else {
		fmt.Printf("Create success: %t\t", createResponse.ResponseHeader.Succeeded)
	}
}

Flex Fields

Common usage for Splitit PHP SDK is in making necessary server-side requests as part of FlexFields product integration. The code below is an example of how SDK wrappers can be used to simplify acquiring public token and verifying payment. For more information, please visit FlexFields documentation.

Server-side code consists of two parts: acquiring public token which needs to be passed to FlexFields JS library and verifying payment before order is finalized and shipped.

Getting public token

func get_flexfields_public_token() string {
	ctx := context.TODO()

	client := splitit.NewSandboxAPIClient(
		"_YOUR_API_KEY_",
		"_YOUR_USERNAME_",
		"_YOUR_PASSWORD_",
		splitit.DefaultCulture("en-US"),
	)

	ff := splitit.NewFlexFields(client)
	token, _ := ff.GetPublicToken(ctx, 350, "USD")
	return token
}

Payment verification

func verify_payment(planNumber string, originalAmount float64) {
	ctx := context.TODO()

	client := splitit.NewSandboxAPIClient(
		"_YOUR_API_KEY_",
		"_YOUR_USERNAME_",
		"_YOUR_PASSWORD_",
	)

	ff := splitit.NewFlexFields(client)
	isVerified, _ := ff.VerifyPayment(ctx, planNumber, originalAmount)

	if !isVerified {
		// Respond to potential fraud attempt.
	}
}

For detailed information on request and response procedures, please visit Splitit Web API documentation

Documentation for API Endpoints

All URIs are relative to https://webapi.production.splitit.com

ClassMethodHTTP requestDescription
InfoApiInfoGetLearnMoreDetailsPost /api/Merchant/GetLearnMoreDetails
InfrastructureApiInfrastructureGetResourcesPost /api/Infrastructure/GetResources
InfrastructureApiInfrastructureGetResources2Get /api/Infrastructure/GetResources
InstallmentPlanApiInstallmentPlanApprovePost /api/InstallmentPlan/Approve
InstallmentPlanApiInstallmentPlanCancelPost /api/InstallmentPlan/Cancel
InstallmentPlanApiInstallmentPlanChargeBackPost /api/InstallmentPlan/ChargeBack
InstallmentPlanApiInstallmentPlanCreatePost /api/InstallmentPlan/Create
InstallmentPlanApiInstallmentPlanGetPost /api/InstallmentPlan/Get
InstallmentPlanApiInstallmentPlanGet3DSecureParametersPost /api/InstallmentPlan/Get3DSecureParameters
InstallmentPlanApiInstallmentPlanGetExtendedPost /api/InstallmentPlan/GetExtended
InstallmentPlanApiInstallmentPlanGetFraudStatusDisplayPost /api/InstallmentPlan/GetFraudStatusDisplay
InstallmentPlanApiInstallmentPlanGetInitiatedInstallmentPlanRequestPost /api/InstallmentPlan/GetInitiatedInstallmentPlanRequest
InstallmentPlanApiInstallmentPlanGetInitiatedUpdatePaymentDataGet /api/InstallmentPlan/GetInitiatedUpdatePaymentData
InstallmentPlanApiInstallmentPlanGetLearnMoreDetailsPost /api/InstallmentPlan/GetLearnMoreDetails
InstallmentPlanApiInstallmentPlanGetPGTLPost /api/InstallmentPlan/GetPGTL
InstallmentPlanApiInstallmentPlanGetSchedulesPost /api/InstallmentPlan/GetSchedules
InstallmentPlanApiInstallmentPlanInitiatePost /api/InstallmentPlan/Initiate
InstallmentPlanApiInstallmentPlanRefundPost /api/InstallmentPlan/Refund
InstallmentPlanApiInstallmentPlanRequestPaymentPost /api/InstallmentPlan/RequestPayment
InstallmentPlanApiInstallmentPlanStartInstallmentsPost /api/InstallmentPlan/StartInstallments
InstallmentPlanApiInstallmentPlanTermsAndConditionsPost /api/InstallmentPlan/TermsAndConditions
InstallmentPlanApiInstallmentPlanTestCardPost /api/InstallmentPlan/TestCard
InstallmentPlanApiInstallmentPlanUpdatePost /api/InstallmentPlan/Update
InstallmentPlanApiInstallmentPlanVerifyPaymentPost /api/InstallmentPlan/Get/VerifyPayment
LoginApiLoginPostPost /api/Login

Documentation For Models

Documentation For Authorization

Usually, login request is performed server-side, sessionId is acquired and publicToken is obtained by calling InstallmentPlanApi.InstallmentPlanInitiate. For that particular transaction, publicToken should be used on client side for maximum security.

Author

Splitit