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

StripePI: Skip add_network_token_cryptogram_and_eci method to accept ApplePay recurring payments #5212

Merged

Conversation

sinourain
Copy link
Contributor

@sinourain sinourain commented Aug 13, 2024

Summary:

StripePI: Skip add_network_token_cryptogram_and_eci method to accept ApplePay recurring payments and add unit/remote tests

SER-3618

Remote Test:

Loaded suite test/remote/gateways/remote_stripe_payment_intents_test
Started
Finished in 255.69074 seconds.
97 tests, 460 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
0.38 tests/s, 1.80 assertions/s

Unit Tests:

Finished in 29.539052 seconds.
5993 tests, 80199 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
202.88 tests/s, 2715.02 assertions/s

RuboCop:

798 files inspected, no offenses detected

Copy link
Contributor

@aenand aenand left a comment

Choose a reason for hiding this comment

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

We need to prevent sending cryptogram and eci if the stored_credential[:initiator] == 'merchant'

@sinourain sinourain force-pushed the ECS-3618_Stripe_PI_Stored_Credentials_for_ApplePay branch 3 times, most recently from 455ab09 to fad0e58 Compare August 16, 2024 17:39
@sinourain
Copy link
Contributor Author

We need to prevent sending cryptogram and eci if the stored_credential[:initiator] == 'merchant'

Good catch, done!

@sinourain sinourain force-pushed the ECS-3618_Stripe_PI_Stored_Credentials_for_ApplePay branch from fad0e58 to 49d354c Compare August 16, 2024 20:56
@sinourain sinourain requested a review from aenand August 16, 2024 20:56
@sinourain sinourain force-pushed the ECS-3618_Stripe_PI_Stored_Credentials_for_ApplePay branch from 49d354c to 1ee70c2 Compare August 16, 2024 21:07
@@ -38,7 +38,7 @@ def create_intent(money, payment_method, options = {})
return result if result.is_a?(ActiveMerchant::Billing::Response)
end

add_network_token_cryptogram_and_eci(post, payment_method)
add_network_token_cryptogram_and_eci(post, payment_method, options)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does Apple Pay and Google Pay also add these values in add_digital_wallet? It seems a bit confusing if the new AP route hits this method twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Fixed!

Comment on lines 319 to 322
def adding_network_token_card_data?(payment_method, options = {})
return true if payment_method.is_a?(ActiveMerchant::Billing::NetworkTokenizationCreditCard) &&
payment_method.source == :network_token &&
payment_method.source != :apple_pay &&
options.dig(:stored_credential, :initiator) != 'merchant'
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def adding_network_token_card_data?(payment_method, options = {})
return true if payment_method.is_a?(ActiveMerchant::Billing::NetworkTokenizationCreditCard) &&
payment_method.source == :network_token &&
payment_method.source != :apple_pay &&
options.dig(:stored_credential, :initiator) != 'merchant'
def add_network_token_card_data?(payment_method, options = {})
return true if payment_method.is_a?(ActiveMerchant::Billing::NetworkTokenizationCreditCard) &&
payment_method.source == :network_token &&
options.dig(:stored_credential, :initiator) != 'merchant'

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need two source checks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

@sinourain sinourain force-pushed the ECS-3618_Stripe_PI_Stored_Credentials_for_ApplePay branch from 1ee70c2 to 78f4a97 Compare August 20, 2024 15:57
def adding_network_token_card_data?(payment_method)
return true if payment_method.is_a?(ActiveMerchant::Billing::NetworkTokenizationCreditCard) && payment_method.source == :network_token
def adding_network_token_card_data?(payment_method, options = {})
return true if payment_method.is_a?(ActiveMerchant::Billing::NetworkTokenizationCreditCard) &&

Choose a reason for hiding this comment

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

Can we just leave this method as it was before? I rather remove it from add_network_token_cryptogram_and_eci. adding_network_token_card_data? is used in other methods and I wouldn't want us to break anything else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, done!

def add_network_token_cryptogram_and_eci(post, payment_method)
return unless adding_network_token_card_data?(payment_method)
def add_network_token_cryptogram_and_eci(post, payment_method, options)
return unless !options[:wallet_type] || adding_network_token_card_data?(payment_method, options)
Copy link

@almalee24 almalee24 Aug 20, 2024

Choose a reason for hiding this comment

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

I think it would be better to update this to be something like

return unless payment_method.is_a(NetworkTokenizationCreditCard)
return if options[:stored_credential] && options.dig(:stored_credential, :initiator) == 'merchant'

Choose a reason for hiding this comment

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

We only pass options[:wallet_type] when the payment method is a non tokenized GooglePay and in AM the payment method model for this would be CreditCard

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, thanks!


post[:payment_method_options] ||= {}
post[:payment_method_options][:card] ||= {}
post[:payment_method_options][:card][:network_token] ||= {}
post[:payment_method_options][:card][:network_token][:cryptogram] = payment_method.payment_cryptogram if payment_method.payment_cryptogram
post[:payment_method_options][:card][:network_token][:electronic_commerce_indicator] = payment_method.eci if payment_method.eci
post[:payment_method_options][:card][:network_token] = {

Choose a reason for hiding this comment

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

Also if post[:payment_method_options][:card][:network_token] already exist we would have to use merge! because here we are resetting the object.

Choose a reason for hiding this comment

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

So you could do something like

post[:payment_method_options][:card][:network_token].merge!({
  cryptogram: payment_method.respond_to?(:payment_cryptogram) ? payment_method.payment_cryptogram : options[:cryptogram],
          electronic_commerce_indicator: format_eci(payment_method, options)
 }.compact)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@sinourain sinourain force-pushed the ECS-3618_Stripe_PI_Stored_Credentials_for_ApplePay branch from 78f4a97 to 9649f56 Compare August 20, 2024 20:41
@@ -317,7 +317,8 @@ def digital_wallet_payment_method?(payment_method)
end

def adding_network_token_card_data?(payment_method)
return true if payment_method.is_a?(ActiveMerchant::Billing::NetworkTokenizationCreditCard) && payment_method.source == :network_token
return true if payment_method.is_a?(ActiveMerchant::Billing::NetworkTokenizationCreditCard) &&
payment_method.source == :network_token
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this check for source?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I checked and it is not necessary

@sinourain sinourain force-pushed the ECS-3618_Stripe_PI_Stored_Credentials_for_ApplePay branch from 9649f56 to fed72da Compare August 21, 2024 13:30
Comment on lines 319 to 323
def adding_network_token_card_data?(payment_method)
return true if payment_method.is_a?(ActiveMerchant::Billing::NetworkTokenizationCreditCard) && payment_method.source == :network_token
return true if payment_method.is_a?(ActiveMerchant::Billing::NetworkTokenizationCreditCard)

false
end
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about updating this method to have the check for options.dig(:stored_credential, :initiator) != 'merchant' as well so that the add_network_token_cryptogram_and_eci method can just rely on this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, done!

@sinourain sinourain force-pushed the ECS-3618_Stripe_PI_Stored_Credentials_for_ApplePay branch from fed72da to 98afaef Compare August 21, 2024 15:08
Copy link
Contributor

@aenand aenand left a comment

Choose a reason for hiding this comment

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

LGTM :shipit: Please make sure all of Alma's feedback is addressed!

@@ -316,8 +316,8 @@ def digital_wallet_payment_method?(payment_method)
payment_method.source == :google_pay || payment_method.source == :apple_pay
end

def adding_network_token_card_data?(payment_method)
return true if payment_method.is_a?(ActiveMerchant::Billing::NetworkTokenizationCreditCard) && payment_method.source == :network_token
def adding_network_token_card_data?(payment_method, options = {})
Copy link

@almalee24 almalee24 Aug 21, 2024

Choose a reason for hiding this comment

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

I would prefer this stay as it is in master. adding_network_token_card_data? is used in 4 other places and I do not want to alter how that is working at the moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, no problem :)

def add_network_token_cryptogram_and_eci(post, payment_method)
return unless adding_network_token_card_data?(payment_method)
def add_network_token_cryptogram_and_eci(post, payment_method, options)
return unless adding_network_token_card_data?(payment_method, options)

Choose a reason for hiding this comment

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

This should be updated to return unless payment_method.is_a?(NetworkTokenizationCreditCard) && options.dig(:stored_credential, :initiator) != 'merchant'

Choose a reason for hiding this comment

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

Only AP/GP transactions on the new flow would reach here since if it was on the old flow the payment_method would be a token

Choose a reason for hiding this comment

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

If we want to just be safe that it's only AP/GP new flow on this we could do something like

return unless payment_method.is_a?(NetworkTokenizationCreditCard) && options.dig(:stored_credential, :initiator) != 'merchant'
return if digital_wallet_payment_method?(payment_method) && options[:new_ap_gp_route] != true

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, done!

@sinourain sinourain force-pushed the ECS-3618_Stripe_PI_Stored_Credentials_for_ApplePay branch from 98afaef to d005d06 Compare August 22, 2024 15:42
@sinourain sinourain changed the title StripePI: Update tests to accept ApplePay recurring payments StripePI: Skip add_network_token_cryptogram_and_eci method to accept ApplePay recurring payments Aug 22, 2024
@almalee24 almalee24 force-pushed the ECS-3618_Stripe_PI_Stored_Credentials_for_ApplePay branch from d005d06 to 23a3389 Compare August 28, 2024 19:35
Summary:
------------------------------
StripePI: Skip add_network_token_cryptogram_and_eci method to accept ApplePay recurring payments and add unit/remote tests

[SER-3618](https://spreedly.atlassian.net/browse/ECS-3618)

Remote Test:
------------------------------
Loaded suite test/remote/gateways/remote_stripe_payment_intents_test
Started
Finished in 255.69074 seconds.
97 tests, 460 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
0.38 tests/s, 1.80 assertions/s

Unit Tests:
------------------------------
Finished in 29.539052 seconds.
5993 tests, 80199 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
202.88 tests/s, 2715.02 assertions/s

RuboCop:
------------------------------
798 files inspected, no offenses detected
@almalee24 almalee24 force-pushed the ECS-3618_Stripe_PI_Stored_Credentials_for_ApplePay branch from 23a3389 to 3d28e30 Compare August 29, 2024 14:48
@almalee24 almalee24 merged commit 3d28e30 into master Aug 29, 2024
5 checks passed
@almalee24 almalee24 deleted the ECS-3618_Stripe_PI_Stored_Credentials_for_ApplePay branch August 29, 2024 14:55
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.

3 participants