Skip to content

Commit

Permalink
add sca info when using credit card for paypal rtau (#229)
Browse files Browse the repository at this point in the history
* add sca info when using credit card for paypal rtau

* add logging for debugging purposes

* delete logging lines
  • Loading branch information
MiguelGomezMaxio authored Oct 2, 2024
1 parent 4c39a71 commit bdc3248
Showing 1 changed file with 42 additions and 13 deletions.
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

0 comments on commit bdc3248

Please sign in to comment.