Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/models/spree/adyen/notification_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def create_missing_payment
amount: notification.money.dollars,
# We have no idea what payment method they used, this will be
# updated when/if they get redirected
payment_method: Spree::Gateway::AdyenHPP.last,
payment_method: payment_method_for(order),
response_code: notification.psp_reference,
source: source,
order: order
Expand All @@ -143,6 +143,12 @@ def create_missing_payment
payment
end

def payment_method_for(order)
Copy link
Member

@luukveenis luukveenis Jun 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't need to pass the order to this method since the class is initialized with it. With it removed the method can probably also be renamed to something like hpp_payment_method.

order.store.payment_methods.where(type: 'Spree::Gateway::AdyenHPP', active: true).last!
rescue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a big fan of rescuing everything, I would prefer something like:
order.store.payment_methods.active.find_by(type: "Spree::Gateway::AdyenHPP") || Spree::Gateway::AdyenHPP.last

Spree::Gateway::AdyenHPP.last
end

def should_create_payment?
notification.authorisation? &&
notification.success? &&
Expand Down
31 changes: 27 additions & 4 deletions spec/models/spree/adyen/notification_processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,33 @@
create(:notification, :auth, order: order)
end

it "creates a payment" do
expect { subject }.
to change { order.payments.count }.
to 1
context "creates a payment" do
it do
expect { subject }.
to change { order.payments.count }.
to 1
end

it "is store specific" do
store_specific_payment_method = create(:spree_gateway_adyen_hpp)

order.store.payment_methods << store_specific_payment_method

_other_payment_method = create(:spree_gateway_adyen_hpp)

expect(
subject.order.payments.last.payment_method
).to eq(store_specific_payment_method)
end

it "is default" do
other_payment_method = create(:spree_gateway_adyen_hpp)

expect(
subject.order.payments.last.payment_method
).to eq(other_payment_method)
end

end

it "completes the order" do
Expand Down