From d658cb1147c6231c7ff9780e86d137d348aecd1a Mon Sep 17 00:00:00 2001 From: postables Date: Tue, 28 Apr 2020 16:20:47 -0700 Subject: [PATCH 1/3] add api route to purchase temporalx license --- api/v2/routes_payment.go | 55 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/api/v2/routes_payment.go b/api/v2/routes_payment.go index 7ca997596..8fca23b82 100644 --- a/api/v2/routes_payment.go +++ b/api/v2/routes_payment.go @@ -427,6 +427,61 @@ func (api *API) CreateDashPayment(c *gin.Context) { Respond(c, http.StatusOK, gin.H{"response": p}) } +// stripChargeTemporalX enables purchasing the license for TemporalX +func (api *API) stripeChargeTemporalX(c *gin.Context) { + username, err := GetAuthenticatedUserFromContext(c) + if err != nil { + api.LogError(c, err, eh.NoAPITokenError)(http.StatusBadRequest) + return + } + forms, missingField := api.extractPostForms(c, "stripe_token", "stripe_email") + if missingField != "" { + FailWithMissingField(c, missingField) + return + } + // set the secret key after input validation + stripe.Key = api.cfg.Stripe.SecretKey + // set the source for the charge + // in this case it is a tokenized version of the credit card + source, err := stripe.SourceParamsFor(forms["stripe_token"]) + if err != nil { + Fail(c, err) + return + } + // initialize credit card charge parameters + ch, err := charge.New(&stripe.ChargeParams{ + Amount: stripe.Int64(299), + Currency: stripe.String(string(stripe.CurrencyUSD)), + Description: stripe.String("temporalx 3-node license purchase"), + // StatementDescriptor is what appears in their credit card billing report + StatementDescriptor: stripe.String("credit purchase"), + // email the receipt goes to + ReceiptEmail: stripe.String(forms["stripe_email"]), + Source: source, + Params: stripe.Params{ + Metadata: map[string]string{ + "order_type": "temporal.credits", + }, + }, + }) + if err != nil { + api.LogError(c, err, err.Error())(http.StatusBadRequest) + return + } + api.l.Infow("payment complete", "payment.method", "stripe", "user", username, "charge", ch) + if err := api.queues.email.PublishMessage(queue.EmailSend{ + Subject: "TemporalX License Purchase", + Content: username + " has purchased a 3 node license for TemporalX", + ContentType: "text/html", + UserNames: []string{username}, + Emails: []string{"admin@rtradetechnologies.com"}, + }); err != nil { + api.LogError(c, err, eh.QueuePublishError)(http.StatusBadRequest) + return + } + Respond(c, http.StatusOK, gin.H{"response": "temporalx license purchase succcessful, details will be sent to email on file within 24 hours"}) +} + func (api *API) stripeCharge(c *gin.Context) { username, err := GetAuthenticatedUserFromContext(c) if err != nil { From 232e91f94a35df372e9557e96980bff251203679 Mon Sep 17 00:00:00 2001 From: postables Date: Tue, 28 Apr 2020 16:24:58 -0700 Subject: [PATCH 2/3] api/v2: factor in provincial GST+PST sales tax --- api/v2/routes_payment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/v2/routes_payment.go b/api/v2/routes_payment.go index 8fca23b82..a8d9e9699 100644 --- a/api/v2/routes_payment.go +++ b/api/v2/routes_payment.go @@ -450,7 +450,7 @@ func (api *API) stripeChargeTemporalX(c *gin.Context) { } // initialize credit card charge parameters ch, err := charge.New(&stripe.ChargeParams{ - Amount: stripe.Int64(299), + Amount: stripe.Int64(335), // equivalent to purchase cose + GST&PST provincial taxes Currency: stripe.String(string(stripe.CurrencyUSD)), Description: stripe.String("temporalx 3-node license purchase"), // StatementDescriptor is what appears in their credit card billing report From 0755d28daf8e75943003b2238bfa58f8822d1663 Mon Sep 17 00:00:00 2001 From: postables Date: Tue, 28 Apr 2020 16:27:02 -0700 Subject: [PATCH 3/3] api/v2: update statement description --- api/v2/routes_payment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/v2/routes_payment.go b/api/v2/routes_payment.go index a8d9e9699..70f73a8ad 100644 --- a/api/v2/routes_payment.go +++ b/api/v2/routes_payment.go @@ -454,7 +454,7 @@ func (api *API) stripeChargeTemporalX(c *gin.Context) { Currency: stripe.String(string(stripe.CurrencyUSD)), Description: stripe.String("temporalx 3-node license purchase"), // StatementDescriptor is what appears in their credit card billing report - StatementDescriptor: stripe.String("credit purchase"), + StatementDescriptor: stripe.String("temporalx 3-node license purchase"), // email the receipt goes to ReceiptEmail: stripe.String(forms["stripe_email"]), Source: source,