-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spree::Wallet & Non credit card payment sources #1707
Merged
jordan-brough
merged 30 commits into
solidusio:master
from
Lostmyname:non-credit-card-payment-sources
Mar 13, 2017
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
515a405
Move common payment source specs into shared example file
jordan-brough c08f334
Move common code from CreditCard into PaymentSource
jordan-brough a4434e0
Introduce Wallet and WalletSource classes
jordan-brough cb64c89
Add `PaymentSource#reusable?` concept
jordan-brough 1f4dbf6
StoreCredit temporary workaround
jordan-brough 2dd5293
Rename temporary_credit_card -> temporary_payment_source
jordan-brough 8cdcfc2
Update persist_user_credit_card for the Wallet
jordan-brough 9beab0a
Update assign_default_credit_card for the Wallet
jordan-brough e9c86f5
Allow passing `wallet_source_id` instead of `existing_card_id`
jordan-brough 2435109
Use `wallet_source_id` instead of `existing_card` in frontend
jordan-brough f516b90
Deprecate existing_card and existing_card_id parameters
jordan-brough b43e95e
Allow payment sources that don't have `belongs_to :user`
jordan-brough 458a947
Migrate `CreditCard#default` to Wallet, migrate data, drop column
jordan-brough 97d3f73
Deprecate User#payment_sources
jordan-brough 7dd840d
Update add_after_order_complete for non-PaymentSource sources
jordan-brough 60ef289
Update Spree::StoreCredit to inherit from Spree::PaymentSource
peterberkenbosch abb73a5
Rename the wallet_source to wallet_payment_source
peterberkenbosch c0329e0
Add validation for payment_source on the wallet_payment_source.
peterberkenbosch 5881475
Add another spec for WalletPaymentSource
jordan-brough 224a9bc
Fetch reusable_sources from the wallet
e4611c0
Update comment and fix issue on payment builder
547d459
Update Spree::Gateway for payment sources
ad2a966
Fix deprecation warnings in PaymentSpec
b66c08e
Add specs for `Spree::Wallet`
88b3097
Update credit_cards relation to be in UserPaymentSource module
chrisradford a2a2b5c
Update deprecations to include replacement and deprecator
chrisradford a4585c2
Update specs to use Spree::Deprecation.silence
chrisradford 1b7bba7
Rename wallet #default to #default_wallet_payment_source
chrisradford b11cf28
Update Wallet deprecations to use Spree::Deprecation
jordan-brough 2e3bccf
Update Wallet#default_wallet_payment_source= to accept a wallet payme…
jordan-brough File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,8 @@ class PaymentCreate | |
# @param attributes [Hash,ActionController::Parameters] attributes which are assigned to the new payment | ||
# * :payment_method_id Id of payment method used for this payment | ||
# * :source_attributes Attributes used to build the source of this payment. Usually a {CreditCard} | ||
# * :existing_card_id (Integer) The id of an existing {CreditCard} object to use | ||
# * :existing_card_id (Integer) Deprecated: The id of an existing {CreditCard} object to use | ||
# * :wallet_payment_source_id (Integer): The id of a {WalletPaymentSource} to use | ||
# @param request_env [Hash] rack env of user creating the payment | ||
# @param payment [Payment] Internal use only. Instead of making a new payment, change the attributes for an existing one. | ||
def initialize(order, attributes, payment: nil, request_env: {}) | ||
|
@@ -27,7 +28,13 @@ def build | |
@payment.attributes = @attributes | ||
|
||
if source_attributes[:existing_card_id].present? | ||
Spree::Deprecation.warn( | ||
"Passing existing_card_id to PaymentCreate is deprecated. Use wallet_payment_source_id instead.", | ||
caller, | ||
) | ||
build_existing_card | ||
elsif source_attributes[:wallet_payment_source_id].present? | ||
build_from_wallet_payment_source | ||
else | ||
build_source | ||
end | ||
|
@@ -44,20 +51,33 @@ def build_source | |
if source_attributes.present? && payment_method.try(:payment_source_class) | ||
payment.source = payment_method.payment_source_class.new(source_attributes) | ||
payment.source.payment_method_id = payment_method.id | ||
payment.source.user_id = order.user_id if order | ||
if order && payment.source.respond_to?(:user=) | ||
payment.source.user = order.user | ||
end | ||
end | ||
end | ||
|
||
def build_from_wallet_payment_source | ||
wallet_payment_source_id = source_attributes.fetch(:wallet_payment_source_id) | ||
raise(ActiveRecord::RecordNotFound) if order.user.nil? | ||
wallet_payment_source = order.user.wallet.find(wallet_payment_source_id) | ||
raise(ActiveRecord::RecordNotFound) if wallet_payment_source.nil? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change to a |
||
build_from_payment_source(wallet_payment_source.payment_source) | ||
end | ||
|
||
def build_existing_card | ||
credit_card = available_cards.find(source_attributes[:existing_card_id]) | ||
build_from_payment_source(credit_card) | ||
end | ||
|
||
def build_from_payment_source(payment_source) | ||
# FIXME: does this work? | ||
if source_attributes[:verification_value] | ||
credit_card.verification_value = source_attributes[:verification_value] | ||
payment_source.verification_value = source_attributes[:verification_value] | ||
end | ||
|
||
payment.source = credit_card | ||
payment.payment_method_id = credit_card.payment_method_id | ||
payment.source = payment_source | ||
payment.payment_method_id = payment_source.payment_method_id | ||
end | ||
|
||
def available_cards | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't raise here. An order does not necessarily have a user (guest orders don't have).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method will only be used when there is a user for the order. The next line will fail with a
NoMethodError: undefined method 'wallet' for nil:NilClass
if there isn't a user.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, but why raise then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this to start of method with:
return if user.order.nil?