Skip to content
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

Merged
merged 3 commits into from
Jun 18, 2019

Conversation

anbugal
Copy link
Contributor

@anbugal anbugal commented May 30, 2019

BitPay gateway implements API v2 authentication for newer implementations

@@ -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)
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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
    )

Copy link
Contributor Author

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

Copy link
Contributor

@pi3r pi3r Jun 3, 2019

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pi3r Done, thanks

@anbugal anbugal changed the title BitPay - v2 api updates [Bitpay] Add token check for API v2 endpoints Jun 4, 2019
@pi3r pi3r merged commit a1089df into activemerchant:master Jun 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants