Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
Validate payment_type on source
Browse files Browse the repository at this point in the history
The payment_type is used to differ payment soruces. I.E. lots of query methods uses this column to decide which kind of payment this source instance is, even presentor methods uss this clumn to look up the human name in the translation files by this column.

Therefore it is necessary to validate its presence and add a not null constrained in the database.
  • Loading branch information
tvdeyen committed May 15, 2017
1 parent fcd37c8 commit c6f5ec7
Show file tree
Hide file tree
Showing 10 changed files with 384 additions and 312 deletions.
2 changes: 2 additions & 0 deletions app/models/solidus_paypal_braintree/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class Source < ApplicationRecord

belongs_to :customer, class_name: "SolidusPaypalBraintree::Customer"

validates :payment_type, inclusion: [PAYPAL, APPLE_PAY, CREDIT_CARD]

scope(:with_payment_profile, -> { joins(:customer) })
scope(:credit_card, -> { where(payment_type: CREDIT_CARD) })

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class AddNotNullConstraintToSourcesPaymentType < ActiveRecord::Migration
def change
reversible do |dir|
dir.up do
SolidusPaypalBraintree::Source.where(payment_type: nil).
update_all(payment_type: 'CreditCard')
end
end
change_column_null(:solidus_paypal_braintree_sources, :payment_type, false)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"payment_method_id" => payment_method.id,
"source_attributes" => {
"nonce" => "fake-paypal-future-nonce",
"payment_type" => "PayPal"
"payment_type" => SolidusPaypalBraintree::Source::PAYPAL
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
{
transaction: {
nonce: "fake-valid-nonce",
payment_type: "MonopolyMoney",
payment_type: SolidusPaypalBraintree::Source::PAYPAL,
phone: "1112223333",
email: "[email protected]",
address_attributes: {
Expand Down
211 changes: 111 additions & 100 deletions spec/fixtures/cassettes/checkout/resubmit_credit_card.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c6f5ec7

Please sign in to comment.