From 8d1d921e4e4e8e7c60f4a5ffd8113c29474bfbd2 Mon Sep 17 00:00:00 2001 From: Taylor Scott Date: Thu, 31 Oct 2019 22:26:26 -0700 Subject: [PATCH] Update app/controllers/solidus_paypal_braintree/client_tokens_controller.rb Co-Authored-By: Thomas von Deyen --- .../solidus_paypal_braintree/client_tokens_controller.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/solidus_paypal_braintree/client_tokens_controller.rb b/app/controllers/solidus_paypal_braintree/client_tokens_controller.rb index da4ef848..e216fcd7 100644 --- a/app/controllers/solidus_paypal_braintree/client_tokens_controller.rb +++ b/app/controllers/solidus_paypal_braintree/client_tokens_controller.rb @@ -7,7 +7,12 @@ class ClientTokensController < ::Spree::Api::BaseController before_action :load_gateway def create - render json: { client_token: generate_token, payment_method_id: @gateway.id } + token = @gateway.generate_token + if token + render json: { client_token: token, payment_method_id: @gateway.id } + else + render json: { error: Gateway::TOKEN_GENERATION_DISABLED_MESSAGE }, status: 422 + end end private