This repository has been archived by the owner on Mar 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for listing standalone transactions
- Loading branch information
Showing
5 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
app/controllers/api/stateless/braintree/transactions_controller.rb
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Api | ||
module Stateless | ||
module Braintree | ||
class TransactionsController < StatelessController | ||
before_filter :authenticate_request! | ||
|
||
def index | ||
@transactions = PaymentHelper::Braintree.transactions_for_member(@current_member) | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
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
3 changes: 3 additions & 0 deletions
3
app/views/api/stateless/braintree/transactions/index.json.jbuilder
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
json.array! @transactions do |transaction| | ||
json.(transaction, :id, :status, :amount, :created_at) | ||
end |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require 'rails_helper' | ||
|
||
describe 'API::Stateless Subscriptions' do | ||
include Requests::JsonHelpers | ||
include AuthToken | ||
let!(:member) { create(:member, email: 'test@example.com') } | ||
let!(:customer) { create(:payment_braintree_customer, member: member) } | ||
let!(:subscription) { create(:payment_braintree_subscription, customer: customer) } | ||
let!(:subscription_transaction) { create(:payment_braintree_transaction, subscription: subscription, customer: customer ) } | ||
let!(:standalone_transaction_a) { create(:payment_braintree_transaction, customer: customer ) } | ||
let!(:standalone_transaction_b) { create(:payment_braintree_transaction, customer: customer ) } | ||
|
||
before :each do | ||
member.create_authentication(password: 'password') | ||
end | ||
|
||
def auth_headers | ||
token = encode_jwt(member.token_payload) | ||
{ authorization: "Bearer #{token}" } | ||
end | ||
|
||
describe 'GET index' do | ||
it 'returns a list of stand-alone transactions for member' do | ||
get '/api/stateless/braintree/transactions', nil, auth_headers | ||
expect(response.status).to eq(200) | ||
expect(json_hash).to include({ | ||
id: standalone_transaction_a.id, | ||
status: standalone_transaction_a.status, | ||
amount: standalone_transaction_a.amount, | ||
created_at: standalone_transaction_a.created_at | ||
}.as_json) | ||
expect(json_hash).to include({ | ||
id: standalone_transaction_b.id, | ||
status: standalone_transaction_b.status, | ||
amount: standalone_transaction_b.amount, | ||
created_at: standalone_transaction_b.created_at | ||
}.as_json) | ||
end | ||
it 'does not list transactions that are associated with subscriptions' do | ||
get '/api/stateless/braintree/transactions', nil, auth_headers | ||
expect(response.status).to eq(200) | ||
expect(json_hash).to_not include({ | ||
id: subscription_transaction.id, | ||
status: subscription_transaction.status, | ||
amount: subscription_transaction.amount, | ||
created_at: subscription_transaction.created_at | ||
}.as_json) | ||
end | ||
end | ||
|
||
end | ||
|
||
|
||
|