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

add sca info when using credit card for paypal rtau #229

Merged
merged 3 commits into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 42 additions & 13 deletions lib/active_merchant/billing/gateways/paypal_complete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,49 @@ def add_token(params, token_id)

def add_payment_source(post, vault_id, options)
post[:payment_source] ||= {}
payment_source = options[:payment_type] == "paypal_account" ? :paypal : :card
post[:payment_source][payment_source] = {
vault_id: vault_id,
experience_context: {
payment_method_preference: "IMMEDIATE_PAYMENT_REQUIRED",
brand_name: "Maxio",
locale: "en-US",
landing_page: "LOGIN",
shipping_preference: physical_retail?(options) ? "SET_PROVIDED_ADDRESS" : "NO_SHIPPING",
user_action: "PAY_NOW",
# Placeholder values
return_url: "https://example.com/returnUrl",
cancel_url: "https://example.com/cancelUrl"
post[:payment_source] = create_payment_source_body(options, vault_id)
end

def create_payment_source_body(options, vault_id)
payment_source_in_use = options[:payment_type] == "paypal_account" ? :paypal : :card
if payment_source_in_use == :card
{
"token": {
id: vault_id,
type: 'PAYMENT_METHOD_TOKEN'
},
stored_credential: sca_indicators, # this hash corresponds to the SCA payment indicators, which are needed to trigger RTAU
experience_context: experience_context_body(options)
}
else
{
payment_source: {
vault_id: vault_id,
experience_context: experience_context_body(options)
}
}
end
end

def sca_indicators
{
payment_initiator: 'MERCHANT',
payment_type: 'RECURRING',
usage: 'SUBSEQUENT'
}
end

def experience_context_body(options)
{
payment_method_preference: "IMMEDIATE_PAYMENT_REQUIRED",
brand_name: "Maxio",
locale: "en-US",
landing_page: "LOGIN",
shipping_preference: physical_retail?(options) ? "SET_PROVIDED_ADDRESS" : "NO_SHIPPING",
user_action: "PAY_NOW",
# Placeholder values
return_url: "https://example.com/returnUrl",
cancel_url: "https://example.com/cancelUrl"
}
end

Expand Down