From 2cb6e395dc3faf371febf82ec716a0dce4c6a663 Mon Sep 17 00:00:00 2001 From: BlockChyp SDK Builder Date: Thu, 12 Sep 2024 15:49:26 +0000 Subject: [PATCH] Merge pull request #281 from blockchyp/develop Develop to Master --- README.md | 61 +++++++++++++++++++ blockchyp.go | 15 +++++ cli.go | 1 + cmd/blockchyp/main.go | 55 +++++++++++++++++ models.go | 56 +++++++++++++++++ pkg/examples/add_gateway_merchant_example.go | 41 +++++++++++++ .../update_merchant_platforms_example.go | 4 +- pkg/itests/add_gateway_merchant_test.go | 44 +++++++++++++ 8 files changed, 274 insertions(+), 3 deletions(-) create mode 100644 pkg/examples/add_gateway_merchant_example.go create mode 100644 pkg/itests/add_gateway_merchant_test.go diff --git a/README.md b/README.md index 7bbf360..d2bc665 100644 --- a/README.md +++ b/README.md @@ -5273,6 +5273,67 @@ func inviteMerchantUserExample() { ``` +#### Add Gateway Merchant + + + +* **API Credential Types:** Partner +* **Required Role:** Gateway Boarding + +This is a partner level API that can be used to manually board gateway merchants. Use this API in conjunction +with Platform Configuration to instantly board gateway merchants. Note that most partners don't have +permission to do this and are unlikely to get it. + +Settings can be changed by using the Update Merchant API. + + + + +```go +package main + +import ( + "fmt" + "log" + + blockchyp "github.com/blockchyp/blockchyp-go/v2" +) + +func addGatewayMerchantExample() { + // sample credentials + creds := blockchyp.APICredentials{ + APIKey: "ZDSMMZLGRPBPRTJUBTAFBYZ33Q", + BearerToken: "ZLBW5NR4U5PKD5PNP3ZP3OZS5U", + SigningKey: "9c6a5e8e763df1c9256e3d72bd7f53dfbd07312938131c75b3bfd254da787947", + } + + // instantiate the client + client := blockchyp.NewClient(creds) + + // setup request object + request := blockchyp.AddGatewayMerchantRequest{ + Profile: blockchyp.MerchantProfile{ + DBAName: "DBA Name", + CompanyName: "Corporate Entity Name", + }, + } + + response, err := client.AddGatewayMerchant(request) + + if err != nil { + log.Fatal(err) + } + + //process the result + if response.Success { + fmt.Println("Success") + } + + fmt.Printf("Response: %+v\n", response) +} + +``` + #### Add Test Merchant diff --git a/blockchyp.go b/blockchyp.go index 574e82d..49f15df 100644 --- a/blockchyp.go +++ b/blockchyp.go @@ -1555,6 +1555,21 @@ func (client *Client) InviteMerchantUser(request InviteMerchantUserRequest) (*Ac return &response, err } +// AddGatewayMerchant adds a live gateway merchant account. +func (client *Client) AddGatewayMerchant(request AddGatewayMerchantRequest) (*MerchantProfileResponse, error) { + var response MerchantProfileResponse + + err := client.DashboardRequest("/api/add-gateway-merchant", "POST", request, &response, request.Timeout) + + if err, ok := err.(net.Error); ok && err.Timeout() { + response.ResponseDescription = ResponseTimedOut + } else if err != nil { + response.ResponseDescription = err.Error() + } + + return &response, err +} + // AddTestMerchant adds a test merchant account. func (client *Client) AddTestMerchant(request AddTestMerchantRequest) (*MerchantProfileResponse, error) { var response MerchantProfileResponse diff --git a/cli.go b/cli.go index a8a3c51..ba71bde 100644 --- a/cli.go +++ b/cli.go @@ -170,6 +170,7 @@ type CommandLineArguments struct { DeleteProtected bool `json:"deteleProtected"` Roles string `json:"roles"` Notes string `json:"notes"` + CredType string `json:"credType"` } var defaultSettings = &ConfigSettings{ diff --git a/cmd/blockchyp/main.go b/cmd/blockchyp/main.go index 4c52f23..397c7b3 100644 --- a/cmd/blockchyp/main.go +++ b/cmd/blockchyp/main.go @@ -203,6 +203,7 @@ func parseArgs() blockchyp.CommandLineArguments { flag.BoolVar(&args.DeleteProtected, "deleteProtected", false, "protects the credentials from deletion") flag.StringVar(&args.Roles, "roles", "", "an optional array of role codes that will be assigned to the credentials") flag.StringVar(&args.Notes, "notes", "", "free form description of the purpose or intent behind the credentials") + flag.StringVar(&args.CredType, "credType", "", "is the type of credential to be generated, API or TOKENIZING") flag.Parse() if args.Version { @@ -323,6 +324,12 @@ func processCommand(args blockchyp.CommandLineArguments) { processSideLoad(client, args) case "add-test-merchant": processAddTestMerchant(client, args) + case "add-gateway-merchant": + processAddGatewayMerchant(client, args) + case "merchant-platforms": + processMerchantPlatforms(client, args) + case "update-merchant-platforms": + processUpdateMerchantPlatform(client, args) case "delete-test-merchant": processDeleteTestMerchant(client, args) case "invite-merchant-user": @@ -524,6 +531,7 @@ func processMerchantCredentialGeneration(client *blockchyp.Client, args blockchy MerchantID: args.MerchantID, DeleteProtected: args.DeleteProtected, Notes: args.Notes, + CredentialType: args.CredType, } if args.Roles != "" { @@ -2334,6 +2342,53 @@ func processAddTestMerchant(client *blockchyp.Client, args blockchyp.CommandLine dumpResponse(&args, res) } +func processUpdateMerchantPlatform(client *blockchyp.Client, args blockchyp.CommandLineArguments) { + + req := &blockchyp.MerchantPlatform{} + + if !parseJSONInput(args, req) { + handleError(&args, errors.New("unable to parse platform json")) + } + res, err := client.UpdateMerchantPlatforms(*req) + if err != nil { + handleError(&args, err) + } + dumpResponse(&args, res) +} + +func processMerchantPlatforms(client *blockchyp.Client, args blockchyp.CommandLineArguments) { + + req := blockchyp.MerchantProfileRequest{ + MerchantID: args.MerchantID, + } + + res, err := client.MerchantPlatforms(req) + if err != nil { + handleError(&args, err) + } + dumpResponse(&args, res) +} + +func processAddGatewayMerchant(client *blockchyp.Client, args blockchyp.CommandLineArguments) { + + req := &blockchyp.AddGatewayMerchantRequest{} + + if !parseJSONInput(args, req) { + validateRequired(args.CompanyName, "companyName") + req = &blockchyp.AddGatewayMerchantRequest{ + Profile: blockchyp.MerchantProfile{ + DBAName: args.DBAName, + CompanyName: args.CompanyName, + }, + } + } + res, err := client.AddGatewayMerchant(*req) + if err != nil { + handleError(&args, err) + } + dumpResponse(&args, res) +} + func processSlideShows(client *blockchyp.Client, args blockchyp.CommandLineArguments) { req := &blockchyp.SlideShowRequest{} diff --git a/models.go b/models.go index 8699fe0..e503f2d 100644 --- a/models.go +++ b/models.go @@ -4234,6 +4234,19 @@ type AddTestMerchantRequest struct { Timeout int `json:"timeout"` } +// AddGatewayMerchantRequest models basic information needed to create a +// gateway merchant. +type AddGatewayMerchantRequest struct { + // Test specifies whether or not to route transaction to the test gateway. + Test bool `json:"test"` + + // Profile is the merchant profile to be boarded. + Profile MerchantProfile `json:"profile"` + + // Timeout is the request timeout in seconds. + Timeout int `json:"timeout"` +} + // MerchantProfileRequest models a request for information about the merchant // profile. type MerchantProfileRequest struct { @@ -4436,6 +4449,9 @@ type MerchantProfile struct { // MerchantID is the merchant id. MerchantID string `json:"merchantId"` + // BankMid is the primary bank mid. + BankMid string `json:"bankMid"` + // CompanyName is the merchant's company name. CompanyName string `json:"companyName"` @@ -4617,6 +4633,9 @@ type MerchantProfileResponse struct { // MerchantID is the merchant id. MerchantID string `json:"merchantId"` + // BankMid is the primary bank mid. + BankMid string `json:"bankMid"` + // CompanyName is the merchant's company name. CompanyName string `json:"companyName"` @@ -5321,6 +5340,36 @@ type MerchantPlatformsResponse struct { Results []MerchantPlatform `json:"results"` } +// UpdateMerchantPlatformRequest is used to up platform configuration for +// gateway merchants. +type UpdateMerchantPlatformRequest struct { + // Timeout is the request timeout in seconds. + Timeout int `json:"timeout"` + + // Test specifies whether or not to route transaction to the test gateway. + Test bool `json:"test"` + + // Platform is the merchant platform configuration. + Platform MerchantPlatform `json:"platform"` +} + +// UpdateMerchantPlatformResponse echoes back the state of the current +// platform configuration after a change. +type UpdateMerchantPlatformResponse struct { + // Success indicates whether or not the request succeeded. + Success bool `json:"success"` + + // Error is the error, if an error occurred. + Error string `json:"error"` + + // ResponseDescription contains a narrative description of the transaction + // result. + ResponseDescription string `json:"responseDescription"` + + // Platform is the current platform configuration. + Platform MerchantPlatform `json:"platform"` +} + // MerchantPlatform contains details about a merchant board platform // configuration. type MerchantPlatform struct { @@ -7174,6 +7223,10 @@ type MerchantCredentialGenerationRequest struct { // Notes free form description of the purpose or intent behind the // credentials. Notes string `json:"notes"` + + // CredentialType type of credentials to generate, either API or TOKENIZING. + // Defaults to API. + CredentialType string `json:"credentialType"` } // MerchantCredentialGenerationResponse contains merchant api credential data. @@ -7196,6 +7249,9 @@ type MerchantCredentialGenerationResponse struct { // SigningKey is the merchant signing key. SigningKey string `json:"signingKey"` + + // TokenizingKey is the tokenizing key. + TokenizingKey string `json:"tokenizingKey"` } // BuyRateLineItem models a single buy rate calculation line item. diff --git a/pkg/examples/add_gateway_merchant_example.go b/pkg/examples/add_gateway_merchant_example.go new file mode 100644 index 0000000..87ca92d --- /dev/null +++ b/pkg/examples/add_gateway_merchant_example.go @@ -0,0 +1,41 @@ +package main + +import ( + "fmt" + "log" + + blockchyp "github.com/blockchyp/blockchyp-go/v2" +) + +func addGatewayMerchantExample() { + // sample credentials + creds := blockchyp.APICredentials{ + APIKey: "ZDSMMZLGRPBPRTJUBTAFBYZ33Q", + BearerToken: "ZLBW5NR4U5PKD5PNP3ZP3OZS5U", + SigningKey: "9c6a5e8e763df1c9256e3d72bd7f53dfbd07312938131c75b3bfd254da787947", + } + + // instantiate the client + client := blockchyp.NewClient(creds) + + // setup request object + request := blockchyp.AddGatewayMerchantRequest{ + Profile: blockchyp.MerchantProfile{ + DBAName: "DBA Name", + CompanyName: "Corporate Entity Name", + }, + } + + response, err := client.AddGatewayMerchant(request) + + if err != nil { + log.Fatal(err) + } + + //process the result + if response.Success { + fmt.Println("Success") + } + + fmt.Printf("Response: %+v\n", response) +} diff --git a/pkg/examples/update_merchant_platforms_example.go b/pkg/examples/update_merchant_platforms_example.go index ddee240..f35062f 100644 --- a/pkg/examples/update_merchant_platforms_example.go +++ b/pkg/examples/update_merchant_platforms_example.go @@ -19,9 +19,7 @@ func updateMerchantPlatformsExample() { client := blockchyp.NewClient(creds) // setup request object - request := blockchyp.MerchantPlatform{ - MerchantID: "XXXXXXXXXXXXX", - } + request := blockchyp.MerchantPlatform{} response, err := client.UpdateMerchantPlatforms(request) diff --git a/pkg/itests/add_gateway_merchant_test.go b/pkg/itests/add_gateway_merchant_test.go new file mode 100644 index 0000000..e7a40f8 --- /dev/null +++ b/pkg/itests/add_gateway_merchant_test.go @@ -0,0 +1,44 @@ +//go:build integration +// +build integration + +// Copyright 2019-2024 BlockChyp, Inc. All rights reserved. Use of this code +// is governed by a license that can be found in the LICENSE file. +// +// This file was generated automatically by the BlockChyp SDK Generator. +// Changes to this file will be lost every time the code is regenerated. + +package itests + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + blockchyp "github.com/blockchyp/blockchyp-go/v2" +) + +func TestAddGatewayMerchant(t *testing.T) { + assert := assert.New(t) + + config := loadTestConfiguration(t) + client := config.newTestClient(t, "partner") + + // setup request object + request := blockchyp.AddGatewayMerchantRequest{ + Profile: blockchyp.MerchantProfile{ + DBAName: "DBA Name", + CompanyName: "Corporate Entity Name", + }, + } + + logObj(t, "Request:", request) + + response, err := client.AddGatewayMerchant(request) + + assert.NoError(err) + + logObj(t, "Response:", response) + + // response assertions + assert.True(response.Success) +}