Skip to content

Commit

Permalink
Merge pull request #1274 from travis-ci/add_card_fingerprint_am
Browse files Browse the repository at this point in the history
[BSFY-216] Save card fingerprint from Stripe
  • Loading branch information
murtaza-swati authored Mar 22, 2023
2 parents d456c3f + 376bd8b commit 73ab7fd
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/travis/api/v3/billing_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ def update_creditcard(subscription_id, creditcard_token)
handle_subscription_response(response)
end

def update_v2_creditcard(subscription_id, creditcard_token)
response = connection.patch("/v2/subscriptions/#{subscription_id}/creditcard", token: creditcard_token)
def update_v2_creditcard(subscription_id, creditcard_token, creditcard_fingerprint)
response = connection.patch("/v2/subscriptions/#{subscription_id}/creditcard", token: creditcard_token, fingerprint: creditcard_fingerprint)
handle_v2_subscription_response(response)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/travis/api/v3/queries/v2_subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def update_address(user_id)

def update_creditcard(user_id)
client = BillingClient.new(user_id)
client.update_v2_creditcard(params['subscription.id'], params['token'])
client.update_v2_creditcard(params['subscription.id'], params['token'], params['fingerprint'])
end

def changetofree(user_id)
Expand Down
2 changes: 1 addition & 1 deletion lib/travis/api/v3/queries/v2_subscriptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Travis::API::V3
class Queries::V2Subscriptions < Query
params :plan, :coupon, :organization_id, :client_secret, :v1_subscription_id
params :first_name, :last_name, :company, :address, :address2, :city, :country, :state, :vat_id, :zip_code, :billing_email, :has_local_registration, prefix: :billing_info
params :token, prefix: :credit_card_info
params :token, :fingerprint, prefix: :credit_card_info

def all(user_id)
client = BillingClient.new(user_id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Travis::API::V3
class Services::V2Subscription::UpdateCreditcard < Service
params :token
params :token, :fingerprint

def run!
raise LoginRequired unless access_control.full_access_or_logged_in?
Expand Down
2 changes: 1 addition & 1 deletion lib/travis/api/v3/services/v2_subscriptions/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Services::V2Subscriptions::Create < Service
result_type :v2_subscription
params :plan, :coupon, :organization_id, :client_secret, :v1_subscription_id
params :first_name, :last_name, :company, :address, :address2, :city, :country, :state, :vat_id, :zip_code, :billing_email, :has_local_registration, prefix: :billing_info
params :token, prefix: :credit_card_info
params :token, :fingerprint, prefix: :credit_card_info

def run!
raise LoginRequired unless access_control.full_access_or_logged_in?
Expand Down
5 changes: 3 additions & 2 deletions spec/v3/billing_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,12 @@

describe '#update_v2_creditcard' do
let(:creditcard_token) { 'token' }
subject { billing.update_v2_creditcard(subscription_id, creditcard_token) }
let(:creditcard_fingerprint) { 'fingerprint' }
subject { billing.update_v2_creditcard(subscription_id, creditcard_token, creditcard_fingerprint) }

it 'requests the update' do
stubbed_request = stub_billing_request(:patch, "/v2/subscriptions/#{subscription_id}/creditcard", auth_key: auth_key, user_id: user_id)
.with(body: JSON.dump(token: creditcard_token))
.with(body: JSON.dump(token: creditcard_token, fingerprint: creditcard_fingerprint))
.to_return(status: 204)

expect { subject }.to_not raise_error
Expand Down
4 changes: 2 additions & 2 deletions spec/v3/services/v2_subscription/update_creditcard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
let(:token) { Travis::Api::App::AccessToken.create(user: user, app_id: 1) }
let(:headers) {{ 'HTTP_AUTHORIZATION' => "token #{token}",
'CONTENT_TYPE' => 'application/json' }}
let(:creditcard_token) { { 'token' => 'token_from_stripe' } }
let(:creditcard_token) { { 'token' => 'token_from_stripe', 'fingerprint' => 'fingerprint_from_stripe' } }
let(:subscription_id) { rand(999) }

let!(:stubbed_request) do
stub_billing_request(:patch, "/v2/subscriptions/#{subscription_id}/creditcard", auth_key: billing_auth_key, user_id: user.id)
.with(body: { 'token' => 'token_from_stripe' })
.with(body: { 'token' => 'token_from_stripe', 'fingerprint' => 'fingerprint_from_stripe' })
.to_return(status: 204)
end

Expand Down

0 comments on commit 73ab7fd

Please sign in to comment.