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

Commit

Permalink
Merge pull request #527 from SumOfUs/going-cardless-ak
Browse files Browse the repository at this point in the history
Post original payment to AK
  • Loading branch information
osahyoun committed Jun 1, 2016
2 parents 3679d1a + 79b07f6 commit 3111c9d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 22 deletions.
13 changes: 4 additions & 9 deletions app/models/payment/go_cardless/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@ def initialize(subscription, event = {})
def call
Payment::GoCardless.write_transaction(event['links']['payment'], amount, currency, page.id, subscription)

# Hack - ActionKit creates a transaction along with a recurring donation action, so when
# we eventually create our first transaction we don't need to pass this on.
#
if subscription.transactions.count > 1
ChampaignQueue.push(
type: 'subscription-payment',
recurring_id: @subscription.go_cardless_id
)
end
ChampaignQueue.push(
type: 'subscription-payment',
recurring_id: @subscription.go_cardless_id
)
end
end
end
Expand Down
15 changes: 6 additions & 9 deletions lib/payment_processor/clients/braintree/webhook_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,13 @@ def handle_subscription_charged
return
end

# Original transaction was made with the subscription
if subscription.transactions.count > 0
customer = Payment::BraintreeCustomer.find_by(member_id: original_action.member_id)
Payment.write_transaction(@notification, original_action.page_id, original_action.member_id, customer, false)
customer = Payment::BraintreeCustomer.find_by(member_id: original_action.member_id)
Payment.write_transaction(@notification, original_action.page_id, original_action.member_id, customer, false)

ChampaignQueue.push(
type: 'subscription-payment',
recurring_id: original_action.form_data['subscription_id']
)
end
ChampaignQueue.push(
type: 'subscription-payment',
recurring_id: original_action.form_data['subscription_id']
)

end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module Braintree
let(:transactions) { [] }

it 'pushes the transaction to be queued' do
expect(ChampaignQueue).not_to have_received(:push)
expect(ChampaignQueue).to have_received(:push)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,9 @@ module PaymentProcessor::GoCardless
end

context 'first created payment' do
it "doesn't post to queue" do
expect( ChampaignQueue ).not_to have_received(:push)
it "it posts to queue" do
expect( ChampaignQueue ).to have_received(:push)
.with({type: "subscription-payment", recurring_id: "index_ID_123" }).once
end
end

Expand All @@ -334,7 +335,7 @@ module PaymentProcessor::GoCardless

it "posts to queue" do
expect( ChampaignQueue ).to have_received(:push)
.with({type: "subscription-payment", recurring_id: "index_ID_123" })
.with({type: "subscription-payment", recurring_id: "index_ID_123" }).twice
end
end
end
Expand Down

0 comments on commit 3111c9d

Please sign in to comment.