Skip to content

Commit

Permalink
I18n-ize error messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
sauloperez committed May 6, 2021
1 parent 69b91ea commit 9a63f38
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/spree/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def show
if params.key?("payment_intent")
result = ProcessPaymentIntent.new(params["payment_intent"], @order).call!
unless result.ok?
flash[:error] = "The payment could not be processed. #{result.error}"
flash[:error] = "#{I18n.t("payment_could_not_process")}. #{result.error}"
end
@order.reload
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/process_payment_intent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def call!

Result.new(ok: true)
else
Result.new(ok: false, error: "The payment could not be completed")
Result.new(ok: false, error: I18n.t("payment_could_not_complete"))
end

rescue Stripe::StripeError => e
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ en:
height: "Height"
width: "Width"
depth: "Depth"
payment_could_not_process: "The payment could not be processed"
payment_could_not_complete: "The payment could not be completed"

actions:
create_and_add_another: "Create and Add Another"
Expand Down
2 changes: 1 addition & 1 deletion spec/services/process_payment_intent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
result = service.call!

expect(result.ok?).to eq(false)
expect(result.error).to eq("The payment could not be completed")
expect(result.error).to eq(I18n.t("payment_could_not_complete"))
end

it "does not complete the payment" do
Expand Down

0 comments on commit 9a63f38

Please sign in to comment.