Skip to content

Commit

Permalink
Support setting up Amazon Pay (stripe#3390)
Browse files Browse the repository at this point in the history
## Summary
- Support setting up Amazon Pay in PaymentSheet

## Motivation
Amazon Pay GA

## Testing
N/A (Amazon Pay does not yet support SetupIntents, will manually test
this change before GA)

## Changelog
N/A (private beta for now)
  • Loading branch information
porter-stripe authored Mar 11, 2024
1 parent 1804ede commit ec2f31b
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
/* Paypal mandate text */
"By confirming your payment with PayPal, you allow %@ to charge your PayPal account for future payments in accordance with their terms." = "By confirming your payment with PayPal, you allow %@ to charge your PayPal account for future payments in accordance with their terms.";

/* Amazon Pay mandate text */
"By continuing to Amazon Pay, you allow %@ to charge your Amazon Pay account for future payments in accordance with their terms." = "By continuing to Amazon Pay, you allow %@ to charge your Amazon Pay account for future payments in accordance with their terms.";

/* Paypal mandate text */
"By continuing to PayPal, you allow %@ to charge your PayPal account for future payments in accordance with their terms." = "By continuing to PayPal, you allow %@ to charge your PayPal account for future payments in accordance with their terms.";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,11 @@ extension String.Localized {
static var cpf_cpnj: String {
STPLocalizedString("CPF/CPNJ", "Label for CPF/CPNJ (Brazil tax ID) field")
}

static var amazon_pay_mandate_text: String {
STPLocalizedString(
"By continuing to Amazon Pay, you allow %@ to charge your Amazon Pay account for future payments in accordance with their terms.",
"Amazon Pay mandate text"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ extension PaymentSheet {
switch paymentMethod {
case .card:
return []
case .payPal, .cashApp, .revolutPay:
case .payPal, .cashApp, .revolutPay, .amazonPay:
return [.returnURL]
case .USBankAccount, .boleto:
return [.userSupportsDelayedPaymentMethods]
Expand All @@ -220,7 +220,7 @@ extension PaymentSheet {
return [.returnURL, .userSupportsDelayedPaymentMethods]
case .cardPresent, .blik, .weChatPay, .grabPay, .FPX, .giropay, .przelewy24, .EPS,
.netBanking, .OXXO, .afterpayClearpay, .UPI, .klarna, .link, .linkInstantDebit,
.affirm, .paynow, .zip, .amazonPay, .alma, .mobilePay, .unknown, .alipay, .konbini, .promptPay, .swish, .twint:
.affirm, .paynow, .zip, .alma, .mobilePay, .unknown, .alipay, .konbini, .promptPay, .swish, .twint:
return [.unsupportedForSetup]
@unknown default:
return [.unsupportedForSetup]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +557,8 @@ extension PaymentSheet {
paymentMethodType = paymentMethodParams.type
}

// Paypal and Cash App Pay require mandate_data if setting up
if (params.paymentMethodType == .payPal || params.paymentMethodType == .cashApp || params.paymentMethodType == .revolutPay)
&& paymentIntent.setupFutureUsage == .offSession
let requiresMandateData: [STPPaymentMethodType] = [.payPal, .cashApp, .revolutPay, .amazonPay]
if requiresMandateData.contains(paymentMethodType) && paymentIntent.setupFutureUsage == .offSession
{
params.mandateData = .makeWithInferredValues()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ class PaymentSheetFormFactory {
} else if paymentMethod == .revolutPay && saveMode == .merchantRequired {
// special case, display mandate for revolutPay when setting up or pi+sfu
additionalElements = [makeRevolutPayMandate()]
} else if paymentMethod == .amazonPay && saveMode == .merchantRequired {
// special case, display mandate for Amazon Pay when setting up or pi+sfu
additionalElements = [makeAmazonPayMandate()]
} else if paymentMethod == .bancontact {
return makeBancontact()
} else if paymentMethod == .bacsDebit {
Expand Down Expand Up @@ -352,6 +355,11 @@ extension PaymentSheetFormFactory {
return makeMandate(mandateText: mandateText)
}

func makeAmazonPayMandate() -> PaymentMethodElement {
let mandateText = String(format: String.Localized.amazon_pay_mandate_text, configuration.merchantDisplayName)
return makeMandate(mandateText: mandateText)
}

func makePaypalMandate() -> PaymentMethodElement {
let mandateText: String = {
if isPaymentIntent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ class PaymentSheetPaymentMethodTypeTest: XCTestCase {
}

func testPaymentIntentFilteredPaymentMethodTypes_withSetupFutureUsage() {
let intent = Intent._testPaymentIntent(paymentMethodTypes: [.card, .cashApp, .mobilePay], setupFutureUsage: .onSession)
let intent = Intent._testPaymentIntent(paymentMethodTypes: [.card, .cashApp, .mobilePay, .amazonPay], setupFutureUsage: .onSession)
var configuration = PaymentSheet.Configuration()
configuration.returnURL = "http://return-to-url"
configuration.allowsDelayedPaymentMethods = true
Expand All @@ -357,20 +357,20 @@ class PaymentSheetPaymentMethodTypeTest: XCTestCase {
configuration: configuration
)

XCTAssertEqual(types, [.stripe(.card), .stripe(.cashApp)])
XCTAssertEqual(types, [.stripe(.card), .stripe(.cashApp), .stripe(.amazonPay)])
}

func testSetupIntentFilteredPaymentMethodTypes() {
let setupIntent = STPFixtures.makeSetupIntent(paymentMethodTypes: [.card, .cashApp])
let intent = Intent.setupIntent(elementsSession: ._testValue(paymentMethodTypes: ["card", "cashapp"]), setupIntent: setupIntent)
let setupIntent = STPFixtures.makeSetupIntent(paymentMethodTypes: [.card, .cashApp, .amazonPay])
let intent = Intent.setupIntent(elementsSession: ._testValue(paymentMethodTypes: ["card", "cashapp", "amazon_pay"]), setupIntent: setupIntent)
var configuration = PaymentSheet.Configuration()
configuration.returnURL = "http://return-to-url"
let types = PaymentSheet.PaymentMethodType.filteredPaymentMethodTypes(
from: intent,
configuration: configuration
)

XCTAssertEqual(types, [.stripe(.card), .stripe(.cashApp)])
XCTAssertEqual(types, [.stripe(.card), .stripe(.cashApp), .stripe(.amazonPay)])
}

func testSetupIntentFilteredPaymentMethodTypes_withoutOrderedPaymentMethodTypes() {
Expand Down

0 comments on commit ec2f31b

Please sign in to comment.