-
Notifications
You must be signed in to change notification settings - Fork 201
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
[Bitpay] Add token check for API v2 endpoints #323
Conversation
@@ -84,7 +84,10 @@ def create_invoice | |||
request = Net::HTTP::Post.new(uri.request_uri) | |||
request.content_type = "application/json" | |||
request.body = @fields.to_json | |||
request.basic_auth @account, '' | |||
|
|||
unless v2_api_token?(@account) |
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.
Are you sure about the unless
? It means that it will only add the basic auth when it's an api v2 token. Also please add some unit tests to cover this case. Thanks.
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.
@pi3r in this statement, when v2_api_token? is true (so v2 token) the inner code won't be run
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.
Yeah you're right my bad... Can you add tests though?
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.
@pi3r the current tests should be enough for this matter, what else do you think we should cover?
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 current test don't cover this condition branch. You can change this https://github.com/activemerchant/offsite_payments/blob/master/test/unit/integrations/bit_pay/bit_pay_helper_test.rb#L52 to look like:
stub_request(:post, BitPay::API_V1_URL).with(
body: {
orderID: '1234',
price: '500',
currency: 'USD',
posData: { orderId: 1234 }.to_json,
fullNotifications: "true",
transactionSpeed: 'high',
token: @token_v1,
}.to_json,
basic_auth: [@token_v1, ''],
).to_return(
status: 200,
body: { id: @invoice_id }.to_json
)
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.
@pi3r it should be good to go. do you think we can put this on the next deployment? thanks
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.
Can you add a description to your pr and we'll be able to merge it?
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.
@pi3r Done, thanks
BitPay gateway implements API v2 authentication for newer implementations