From 1f79804bd6e02235f19d22b51f8d6f6fe0f45103 Mon Sep 17 00:00:00 2001 From: Sean Date: Wed, 11 Jan 2023 16:30:50 -0700 Subject: [PATCH] Only generate fake checkout card token if ENV is LOCAL --- pkg/service/checkout.go | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/pkg/service/checkout.go b/pkg/service/checkout.go index d98195b2..fd7db0c6 100644 --- a/pkg/service/checkout.go +++ b/pkg/service/checkout.go @@ -56,22 +56,27 @@ func AuthorizeCharge(amount float64, userWallet string, tokenId string) (auth Au } client := payments.NewClient(*config) - // Generate a payment token ID in case we don't yet have one in the front end - // For testing purposes only - card := tokens.Card{ - Type: checkoutCommon.Card, - Number: "4242424242424242", - ExpiryMonth: 2, - ExpiryYear: 2024, - Name: "Customer Name", - CVV: "100", - } - paymentToken, err := CreateToken(&card) - if err != nil { - return auth, common.StringError(err) - } - paymentTokenID := paymentToken.Created.Token - if tokenId != "" { + var paymentTokenID string + if common.IsLocalEnv() { + // Generate a payment token ID in case we don't yet have one in the front end + // For testing purposes only + card := tokens.Card{ + Type: checkoutCommon.Card, + Number: "4242424242424242", + ExpiryMonth: 2, + ExpiryYear: 2024, + Name: "Customer Name", + CVV: "100", + } + paymentToken, err := CreateToken(&card) + if err != nil { + return auth, common.StringError(err) + } + paymentTokenID = paymentToken.Created.Token + if tokenId != "" { + paymentTokenID = tokenId + } + } else { paymentTokenID = tokenId }