diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ef9892..6e479f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,13 @@ All notable changes to this project are documented in this file. `paymentRequest.googlePayAllowPrepaidCards` gives it for the button. Omitted or `true`, the requests are unchanged. Android only ([#87](https://github.com/gmi-software/react-native-pay/issues/87)). +- **`applePayMerchantCategoryCode`** and **`applePayLaterAvailability`** in `PaymentRequest`. + The first sets `PKPaymentRequest.merchantCategoryCode`, an ISO 18245 code from 0 to 9999, so + Apple Pay leaves out the cards that don't accept the category (iOS 18 and later). The second + (`ApplePayLaterAvailability`: `'available'`, `'itemIneligible'`, `'recurringTransaction'`) hides + Apple Pay Later and tells the payer why (iOS 17 and later). Earlier iOS versions ignore them, but + an invalid value fails with `code: 'CONFIGURATION'` on any iOS version. iOS only; Android ignores + both ([#78](https://github.com/gmi-software/react-native-pay/issues/78)). - **`PaymentError` with a `code`.** `usePaymentCheckout` now sets `error` to a `PaymentError`, an `Error` subclass whose `code` is a `PaymentErrorCode`: `'CONFIGURATION'` for an empty cart or an invalid request, `'UNKNOWN'` when native code threw, and the result's `code` (`'UNKNOWN'` if it diff --git a/README.md b/README.md index 9409e2b..80ff98c 100644 --- a/README.md +++ b/README.md @@ -798,6 +798,8 @@ interface PaymentRequest { automaticReload?: AutomaticReloadPaymentRequest; // top-ups, iOS 16+ applePayMultiTokenContexts?: PaymentTokenContext[]; // several merchants, iOS 16+ couponCode?: string; // iOS only, needs onCouponCodeChange + applePayMerchantCategoryCode?: number; // ISO 18245 code, iOS 18+ + applePayLaterAvailability?: string; // ApplePayLaterAvailability value, iOS 17+ // Google Pay specific googlePayMerchantId?: string; googlePayEnvironment?: "TEST" | "PRODUCTION"; @@ -925,6 +927,8 @@ Google Pay accepts at most two decimal places, so three-decimal amounts (`"1.234 Google Pay can leave credit cards out, but not debit cards. On Android, `"Debit"` without `"Credit"` sends `allowCreditCards: false`, which UK gambling merchants must do; prepaid cards stay allowed. `["3DS", "Credit"]` accepts every card type on Android, so check the card on your server if you must refuse debit cards. Give `GooglePayButton` and `payServiceStatus` the same `merchantCapabilities` as the payment. +`applePayMerchantCategoryCode` (an ISO 18245 code from 0 to 9999, iOS 18+) leaves out the cards that don't accept your category. `applePayLaterAvailability` (`"available"`, `"itemIneligible"` or `"recurringTransaction"`, iOS 17+) hides Apple Pay Later and tells the payer why. Earlier iOS versions and Android ignore both; an invalid value fails the payment on iOS. See [`PaymentRequest`](https://gmi-software.github.io/react-native-pay/docs/api/types#paymentrequest). + ### Shipping and contact details Set `billingContactRequired`, `shippingContactRequired`, `emailRequired` or `phoneNumberRequired` to ask the payer for a billing address, a shipping address, an email address or a phone number. Each one fills `billingContact`, `shippingContact`, `emailAddress` or `phoneNumber` in the result and in the second argument of `onAuthorize`, on both platforms. Google Pay only collects a phone number with an address: without `shippingContactRequired`, Android asks for it with at least the billing name, country and postal code. diff --git a/docs/docs/api/types.md b/docs/docs/api/types.md index 7e1eee6..4b0c4d2 100644 --- a/docs/docs/api/types.md +++ b/docs/docs/api/types.md @@ -83,6 +83,8 @@ interface PaymentRequest { automaticReload?: AutomaticReloadPaymentRequest applePayMultiTokenContexts?: PaymentTokenContext[] // several merchants, iOS 16+ couponCode?: string // iOS only, needs onCouponCodeChange + applePayMerchantCategoryCode?: number // ISO 18245 code, iOS 18+ + applePayLaterAvailability?: string // ApplePayLaterAvailability value, iOS 17+ // Google Pay (Android) googlePayMerchantId?: string googlePayEnvironment?: 'TEST' | 'PRODUCTION' @@ -122,6 +124,10 @@ Without `googlePayEnvironment`, Android uses `'TEST'`. When it is omitted, an An `couponCode` is a code already applied, shown in the sheet's coupon field; `paymentItems` must already include its discount. It needs `StartPaymentOptions.onCouponCodeChange`, or the payment fails with `code: 'CONFIGURATION'`. iOS only; Android ignores it. +`applePayMerchantCategoryCode` is your ISO 18245 merchant category code, a whole number from 0 to 9999, for example `5411` for grocery stores. Apple Pay leaves out the cards that don't accept the category. iOS 18 and later use it; earlier versions ignore it. Another value, including a fraction, fails the payment on any iOS version: the result has `code: 'CONFIGURATION'` and `error: 'Invalid merchant category code . Use a whole number from 0 to 9999'`. iOS only; Android ignores it. + +`applePayLaterAvailability` takes an [`ApplePayLaterAvailability`](#applepaylateravailability) value. iOS only; Android ignores it. + --- ## PaymentResult @@ -483,6 +489,21 @@ For example, `'delivery'` shows "Delivery Address" instead of "Shipping Address" --- +## ApplePayLaterAvailability + +Whether the payer may pay with Apple Pay Later, used in `PaymentRequest.applePayLaterAvailability` (iOS 17 and later; earlier versions and Android ignore the field). + +```ts +type ApplePayLaterAvailability = + | 'available' + | 'itemIneligible' + | 'recurringTransaction' +``` + +`'itemIneligible'` and `'recurringTransaction'` hide Apple Pay Later, and the sheet tells the payer why: an item can't be paid over time (gift cards, for example, must not be), or the cart holds a subscription. Without the field, Apple Pay uses `'available'`. Any other value fails the payment on any iOS version: the result has `code: 'CONFIGURATION'` and `error: 'Unknown Apple Pay Later availability "". Use "available", "itemIneligible" or "recurringTransaction"'`. + +--- + ## Pass types (iOS) These iOS-only types appear in payment-related metadata returned by Apple Pay APIs (for example pass details tied to the selected card) and are mostly useful in advanced/native-integrated flows. diff --git a/docs/docs/payment-flow.md b/docs/docs/payment-flow.md index a2ceb3c..b801071 100644 --- a/docs/docs/payment-flow.md +++ b/docs/docs/payment-flow.md @@ -85,7 +85,7 @@ function describeOutcome(result: PaymentResult): string | null { | --- | --- | --- | --- | | `'CANCELLED'` | The sheet closed before the user authorized. | iOS: the sheet closed without an authorization. PassKit doesn't say why, so a sheet that closes by itself also reports a cancel. Debug builds log a warning when the sheet closes within 1 second of appearing (see [Troubleshooting](/docs/troubleshooting#the-apple-pay-sheet-closes-right-away)). Android: the sheet returned `RESULT_CANCELED`, also when the user dismisses Google's sign-in prompt, or a Google Pay error has `CANCELED` / `ERROR_CODE_USER_CANCELLED`. | Nothing. Don't show an error. | | `'IN_PROGRESS'` | Another payment is still in flight. No sheet was shown. | Both: `startPayment` called while a payment hasn't settled (see [`isPaymentInProgress()`](/docs/api/hybrid-payment-handler#ispaymentinprogress)). | Ignore it. The payment in flight settles normally. | -| `'CONFIGURATION'` | The request or the app's setup is invalid. Retrying won't help. | Both: an invalid amount, a negative total, a `currencyCode` or `countryCode` that isn't an upper-case ISO code, an unknown merchant capability, invalid `shippingMethods`, and `supportedNetworks` that is empty, has an unknown name or has no network the platform offers. iOS: no Apple Pay merchant ID, an unknown `shippingType`. Android: more than two decimal places, an unknown `googlePayAllowedAuthMethods` value, `googlePayCheckoutOption: 'completeImmediatePurchase'` with a `'pending'` item, `PRODUCTION` without `googlePayMerchantId`, `googlePayGateway` or `googlePayGatewayMerchantId`, and a Google Pay error with `DEVELOPER_ERROR`, `ERROR_CODE_INVALID_PARAMETERS`, `ERROR_CODE_MERCHANT_ACCOUNT_ERROR` or `ERROR_CODE_UNSUPPORTED_API_VERSION`. | Fix the request or the setup; `error` says what is wrong. Show the user a generic error. | +| `'CONFIGURATION'` | The request or the app's setup is invalid. Retrying won't help. | Both: an invalid amount, a negative total, a `currencyCode` or `countryCode` that isn't an upper-case ISO code, an unknown merchant capability, invalid `shippingMethods`, and `supportedNetworks` that is empty, has an unknown name or has no network the platform offers. iOS: no Apple Pay merchant ID, an unknown `shippingType` or `applePayLaterAvailability`, an `applePayMerchantCategoryCode` that isn't a whole number from 0 to 9999. Android: more than two decimal places, an unknown `googlePayAllowedAuthMethods` value, `googlePayCheckoutOption: 'completeImmediatePurchase'` with a `'pending'` item, `PRODUCTION` without `googlePayMerchantId`, `googlePayGateway` or `googlePayGatewayMerchantId`, and a Google Pay error with `DEVELOPER_ERROR`, `ERROR_CODE_INVALID_PARAMETERS`, `ERROR_CODE_MERCHANT_ACCOUNT_ERROR` or `ERROR_CODE_UNSUPPORTED_API_VERSION`. | Fix the request or the setup; `error` says what is wrong. Show the user a generic error. | | `'NOT_AVAILABLE'` | The device can't show the payment sheet right now. | iOS: PassKit can't create the sheet, which Apple documents for a user who can't pay with any of the request's networks, or can't show it (see [Troubleshooting](/docs/troubleshooting#unable-to-present-payment-authorization)). Android: no current activity, the Google Pay sheet fails to start, and a Google Pay error with `SIGN_IN_REQUIRED`, `API_NOT_CONNECTED`, `ERROR_CODE_BUYER_ACCOUNT_ERROR` or `ERROR_CODE_AUTHENTICATION_FAILURE`. | Offer another payment method. Show the pay button only as [Check availability](/docs/guides/availability#show-the-right-button) describes, from `isSupported` and `hasActiveCard`. | | `'PROVIDER_ERROR'` | Apple Pay, Google Pay or your `onAuthorize` reported a failure. | Both: [`onAuthorize`](/docs/guides/server-processing#charge-before-the-sheet-closes) resolved with `'failure'`, rejected, or didn't settle within 25 seconds. Android: any other Google Pay error, such as a network or internal error, and payment data that is missing or can't be read. | Let the user retry or choose another payment method. After a timeout, your server may still have charged: reconcile the order. | | `'UNKNOWN'` | Anything else. | iOS: an unexpected error while starting the payment. Android: an unexpected result code or exception, or a Google Pay error without a status. | Show a generic error and log `error`. | diff --git a/package/android/src/test/java/com/margelo/nitro/pay/TestFixtures.kt b/package/android/src/test/java/com/margelo/nitro/pay/TestFixtures.kt index eb0b936..354bcd9 100644 --- a/package/android/src/test/java/com/margelo/nitro/pay/TestFixtures.kt +++ b/package/android/src/test/java/com/margelo/nitro/pay/TestFixtures.kt @@ -58,6 +58,8 @@ internal fun paymentRequest( automaticReload = automaticReload, applePayMultiTokenContexts = null, couponCode = null, + applePayMerchantCategoryCode = null, + applePayLaterAvailability = null, googlePayMerchantId = googlePayMerchantId, googlePayEnvironment = environment, googlePayGateway = googlePayGateway, diff --git a/package/ios/HybridPaymentHandler.swift b/package/ios/HybridPaymentHandler.swift index e91ac7b..8868602 100644 --- a/package/ios/HybridPaymentHandler.swift +++ b/package/ios/HybridPaymentHandler.swift @@ -45,6 +45,15 @@ private enum ErrorMessage { static func unknownShippingType(_ shippingType: String) -> String { return "Unknown shipping type \"\(shippingType)\". Use \"shipping\", \"delivery\", \"storePickup\" or \"servicePickup\"" } + + static func invalidMerchantCategoryCode(_ code: Double) -> String { + // NSNumber prints 10000, not 10000.0. + return "Invalid merchant category code \(NSNumber(value: code)). Use a whole number from 0 to 9999" + } + + static func unknownApplePayLaterAvailability(_ availability: String) -> String { + return "Unknown Apple Pay Later availability \"\(availability)\". Use \"available\", \"itemIneligible\" or \"recurringTransaction\"" + } } /// Why a payment ended without success. @@ -119,6 +128,9 @@ struct PaymentRequestBuilder { paymentRequest.shippingType = try convertShippingType(shippingType) } + try configureMerchantCategoryCode(paymentRequest, code: request.applePayMerchantCategoryCode) + try configureApplePayLater(paymentRequest, availability: request.applePayLaterAvailability) + configureContactRequirements(paymentRequest, request: request) return paymentRequest @@ -317,6 +329,38 @@ struct PaymentRequestBuilder { } } + /// Checks the code on every iOS version, so a bad one fails the same + /// everywhere; only iOS 18 and later can use it. + private static func configureMerchantCategoryCode(_ paymentRequest: PKPaymentRequest, code: Double?) throws { + guard let code = code else { return } + guard let rawValue = Int16(exactly: code), (0...9999).contains(rawValue) else { + throw PaymentFailure.configuration(ErrorMessage.invalidMerchantCategoryCode(code)) + } + if #available(iOS 18.0, *) { + paymentRequest.merchantCategoryCode = PKPaymentRequest.MerchantCategoryCode(rawValue: rawValue) + } + } + + /// The `ApplePayLaterAvailability` values, so iOS before 17 checks them too. + private enum ApplePayLater: String { + case available, itemIneligible, recurringTransaction + } + + /// Checks the value on every iOS version, like the category code; + /// Apple Pay Later needs iOS 17. + private static func configureApplePayLater(_ paymentRequest: PKPaymentRequest, availability: String?) throws { + guard let availability = availability else { return } + guard let value = ApplePayLater(rawValue: availability) else { + throw PaymentFailure.configuration(ErrorMessage.unknownApplePayLaterAvailability(availability)) + } + guard #available(iOS 17.0, *) else { return } + switch value { + case .available: paymentRequest.applePayLaterAvailability = .available + case .itemIneligible: paymentRequest.applePayLaterAvailability = .unavailable(.itemIneligible) + case .recurringTransaction: paymentRequest.applePayLaterAvailability = .unavailable(.recurringTransaction) + } + } + private static func configureContactRequirements(_ paymentRequest: PKPaymentRequest, request: PaymentRequest) { if request.billingContactRequired == true { paymentRequest.requiredBillingContactFields = [.postalAddress, .name] diff --git a/package/ios/Tests/PaymentRequestBuilderTests.swift b/package/ios/Tests/PaymentRequestBuilderTests.swift index 0e798e1..2e99c34 100644 --- a/package/ios/Tests/PaymentRequestBuilderTests.swift +++ b/package/ios/Tests/PaymentRequestBuilderTests.swift @@ -252,6 +252,81 @@ final class PaymentRequestBuilderTests: XCTestCase { ) } + func testSetsTheMerchantCategoryCode() throws { + let request = try PaymentRequestBuilder.build(from: paymentRequest( + items: [item("Coffee", "4.99")], + merchantCategoryCode: 5411 + )) + + guard #available(iOS 18.0, *) else { throw XCTSkip("Needs iOS 18") } + XCTAssertEqual(request.merchantCategoryCode?.rawValue, 5411) + } + + func testAcceptsTheEdgesOfTheMerchantCategoryCodeRange() throws { + for code in [0.0, 9999.0] { + let request = try PaymentRequestBuilder.build(from: paymentRequest( + items: [item("Coffee", "4.99")], + merchantCategoryCode: code + )) + if #available(iOS 18.0, *) { + XCTAssertEqual(request.merchantCategoryCode?.rawValue, Int16(code)) + } + } + } + + func testLeavesTheMerchantCategoryCodeAloneWithoutOne() throws { + let request = try PaymentRequestBuilder.build(from: paymentRequest(items: [item("Coffee", "4.99")])) + + guard #available(iOS 18.0, *) else { throw XCTSkip("Needs iOS 18") } + // PassKit's own default, which is 0000 rather than nil on iOS 26. + XCTAssertEqual(request.merchantCategoryCode, PKPaymentRequest().merchantCategoryCode) + } + + func testRejectsAnInvalidMerchantCategoryCode() { + let cases: [(Double, String)] = [ + (-1, "-1"), + (10000, "10000"), + (5411.5, "5411.5"), + (40000, "40000"), + (.nan, "nan"), + ] + for (code, shown) in cases { + assertBuildFails( + paymentRequest(items: [item("Coffee", "4.99")], merchantCategoryCode: code), + with: "Invalid merchant category code \(shown). Use a whole number from 0 to 9999" + ) + } + } + + func testSetsApplePayLaterAvailability() throws { + guard #available(iOS 17.0, *) else { throw XCTSkip("Needs iOS 17") } + func availability(_ value: String) throws -> PKPaymentRequest.ApplePayLaterAvailability { + return try PaymentRequestBuilder.build(from: paymentRequest( + items: [item("Coffee", "4.99")], + applePayLaterAvailability: value + )).applePayLaterAvailability + } + + guard case .available = try availability("available") else { + return XCTFail("Expected available") + } + guard case .unavailable(.itemIneligible) = try availability("itemIneligible") else { + return XCTFail("Expected unavailable(.itemIneligible)") + } + guard case .unavailable(.recurringTransaction) = try availability("recurringTransaction") else { + return XCTFail("Expected unavailable(.recurringTransaction)") + } + } + + func testRejectsUnknownApplePayLaterAvailability() { + for value in ["unavailable", "ItemIneligible", ""] { + assertBuildFails( + paymentRequest(items: [item("Coffee", "4.99")], applePayLaterAvailability: value), + with: "Unknown Apple Pay Later availability \"\(value)\". Use \"available\", \"itemIneligible\" or \"recurringTransaction\"" + ) + } + } + func testAppendsAMerchantTotalToASingleItem() throws { // PassKit shows the last item as the total, so one item still gets one. let request = try PaymentRequestBuilder.build(from: paymentRequest( diff --git a/package/ios/Tests/PaymentSheetSessionTests.swift b/package/ios/Tests/PaymentSheetSessionTests.swift index 302b72b..2595e44 100644 --- a/package/ios/Tests/PaymentSheetSessionTests.swift +++ b/package/ios/Tests/PaymentSheetSessionTests.swift @@ -76,6 +76,8 @@ final class PaymentSheetSessionTests: XCTestCase { automaticReload: nil, applePayMultiTokenContexts: nil, couponCode: nil, + applePayMerchantCategoryCode: nil, + applePayLaterAvailability: nil, googlePayMerchantId: nil, googlePayEnvironment: nil, googlePayGateway: nil, diff --git a/package/ios/Tests/TestFixtures.swift b/package/ios/Tests/TestFixtures.swift index 64e8a0a..2028731 100644 --- a/package/ios/Tests/TestFixtures.swift +++ b/package/ios/Tests/TestFixtures.swift @@ -32,7 +32,9 @@ func paymentRequest( deferred: DeferredPaymentRequest? = nil, automaticReload: AutomaticReloadPaymentRequest? = nil, multiTokenContexts: [PaymentTokenContext]? = nil, - couponCode: String? = nil + couponCode: String? = nil, + merchantCategoryCode: Double? = nil, + applePayLaterAvailability: String? = nil ) -> PaymentRequest { return PaymentRequest( applePayMerchantIdentifier: merchantIdentifier, @@ -54,6 +56,8 @@ func paymentRequest( automaticReload: automaticReload, applePayMultiTokenContexts: multiTokenContexts, couponCode: couponCode, + applePayMerchantCategoryCode: merchantCategoryCode, + applePayLaterAvailability: applePayLaterAvailability, googlePayMerchantId: nil, googlePayEnvironment: nil, googlePayGateway: nil, diff --git a/package/nitrogen/generated/android/c++/JPaymentRequest.hpp b/package/nitrogen/generated/android/c++/JPaymentRequest.hpp index 8406ee1..6258e2b 100644 --- a/package/nitrogen/generated/android/c++/JPaymentRequest.hpp +++ b/package/nitrogen/generated/android/c++/JPaymentRequest.hpp @@ -105,6 +105,10 @@ namespace margelo::nitro::pay { jni::local_ref> applePayMultiTokenContexts = this->getFieldValue(fieldApplePayMultiTokenContexts); static const auto fieldCouponCode = clazz->getField("couponCode"); jni::local_ref couponCode = this->getFieldValue(fieldCouponCode); + static const auto fieldApplePayMerchantCategoryCode = clazz->getField("applePayMerchantCategoryCode"); + jni::local_ref applePayMerchantCategoryCode = this->getFieldValue(fieldApplePayMerchantCategoryCode); + static const auto fieldApplePayLaterAvailability = clazz->getField("applePayLaterAvailability"); + jni::local_ref applePayLaterAvailability = this->getFieldValue(fieldApplePayLaterAvailability); static const auto fieldGooglePayMerchantId = clazz->getField("googlePayMerchantId"); jni::local_ref googlePayMerchantId = this->getFieldValue(fieldGooglePayMerchantId); static const auto fieldGooglePayEnvironment = clazz->getField("googlePayEnvironment"); @@ -184,6 +188,8 @@ namespace margelo::nitro::pay { return __vector; }(applePayMultiTokenContexts)) : std::nullopt, couponCode != nullptr ? std::make_optional(couponCode->toStdString()) : std::nullopt, + applePayMerchantCategoryCode != nullptr ? std::make_optional(applePayMerchantCategoryCode->value()) : std::nullopt, + applePayLaterAvailability != nullptr ? std::make_optional(applePayLaterAvailability->toStdString()) : std::nullopt, googlePayMerchantId != nullptr ? std::make_optional(googlePayMerchantId->toStdString()) : std::nullopt, googlePayEnvironment != nullptr ? std::make_optional(googlePayEnvironment->toCpp()) : std::nullopt, googlePayGateway != nullptr ? std::make_optional(googlePayGateway->toStdString()) : std::nullopt, @@ -209,7 +215,7 @@ namespace margelo::nitro::pay { */ [[maybe_unused]] static jni::local_ref fromCpp(const PaymentRequest& value) { - using JSignature = JPaymentRequest(jni::alias_ref, jni::alias_ref, jni::alias_ref, jni::alias_ref, jni::alias_ref, jni::alias_ref>, jni::alias_ref>, jni::alias_ref>, jni::alias_ref, jni::alias_ref>, jni::alias_ref, jni::alias_ref, jni::alias_ref, jni::alias_ref, jni::alias_ref, jni::alias_ref, jni::alias_ref, jni::alias_ref>, jni::alias_ref, jni::alias_ref, jni::alias_ref, jni::alias_ref, jni::alias_ref, jni::alias_ref>, jni::alias_ref, jni::alias_ref); + using JSignature = JPaymentRequest(jni::alias_ref, jni::alias_ref, jni::alias_ref, jni::alias_ref, jni::alias_ref, jni::alias_ref>, jni::alias_ref>, jni::alias_ref>, jni::alias_ref, jni::alias_ref>, jni::alias_ref, jni::alias_ref, jni::alias_ref, jni::alias_ref, jni::alias_ref, jni::alias_ref, jni::alias_ref, jni::alias_ref>, jni::alias_ref, jni::alias_ref, jni::alias_ref, jni::alias_ref, jni::alias_ref, jni::alias_ref, jni::alias_ref, jni::alias_ref>, jni::alias_ref, jni::alias_ref); static const auto clazz = javaClassStatic(); static const auto create = clazz->getStaticMethod("fromCpp"); return create( @@ -278,6 +284,8 @@ namespace margelo::nitro::pay { return __array; }(value.applePayMultiTokenContexts.value()) : nullptr, value.couponCode.has_value() ? jni::make_jstring(value.couponCode.value()) : nullptr, + value.applePayMerchantCategoryCode.has_value() ? jni::JDouble::valueOf(value.applePayMerchantCategoryCode.value()) : nullptr, + value.applePayLaterAvailability.has_value() ? jni::make_jstring(value.applePayLaterAvailability.value()) : nullptr, value.googlePayMerchantId.has_value() ? jni::make_jstring(value.googlePayMerchantId.value()) : nullptr, value.googlePayEnvironment.has_value() ? JGooglePayEnvironment::fromCpp(value.googlePayEnvironment.value()) : nullptr, value.googlePayGateway.has_value() ? jni::make_jstring(value.googlePayGateway.value()) : nullptr, diff --git a/package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentRequest.kt b/package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentRequest.kt index f570360..c5eaafa 100644 --- a/package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentRequest.kt +++ b/package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentRequest.kt @@ -77,6 +77,12 @@ data class PaymentRequest( val couponCode: String?, @DoNotStrip @Keep + val applePayMerchantCategoryCode: Double?, + @DoNotStrip + @Keep + val applePayLaterAvailability: String?, + @DoNotStrip + @Keep val googlePayMerchantId: String?, @DoNotStrip @Keep @@ -121,6 +127,8 @@ data class PaymentRequest( && Objects.deepEquals(this.automaticReload, other.automaticReload) && Objects.deepEquals(this.applePayMultiTokenContexts, other.applePayMultiTokenContexts) && Objects.deepEquals(this.couponCode, other.couponCode) + && Objects.deepEquals(this.applePayMerchantCategoryCode, other.applePayMerchantCategoryCode) + && Objects.deepEquals(this.applePayLaterAvailability, other.applePayLaterAvailability) && Objects.deepEquals(this.googlePayMerchantId, other.googlePayMerchantId) && Objects.deepEquals(this.googlePayEnvironment, other.googlePayEnvironment) && Objects.deepEquals(this.googlePayGateway, other.googlePayGateway) @@ -151,6 +159,8 @@ data class PaymentRequest( automaticReload, applePayMultiTokenContexts, couponCode, + applePayMerchantCategoryCode, + applePayLaterAvailability, googlePayMerchantId, googlePayEnvironment, googlePayGateway, @@ -169,8 +179,8 @@ data class PaymentRequest( @Keep @Suppress("unused") @JvmStatic - private fun fromCpp(applePayMerchantIdentifier: String?, merchantName: String?, totalLabel: String?, countryCode: String, currencyCode: String, paymentItems: Array, merchantCapabilities: Array, supportedNetworks: Array, shippingType: String?, shippingMethods: Array?, billingContactRequired: Boolean?, shippingContactRequired: Boolean?, emailRequired: Boolean?, phoneNumberRequired: Boolean?, recurring: RecurringPaymentRequest?, deferred: DeferredPaymentRequest?, automaticReload: AutomaticReloadPaymentRequest?, applePayMultiTokenContexts: Array?, couponCode: String?, googlePayMerchantId: String?, googlePayEnvironment: GooglePayEnvironment?, googlePayGateway: String?, googlePayGatewayMerchantId: String?, googlePayAllowedAuthMethods: Array?, googlePayAllowPrepaidCards: Boolean?, googlePayCheckoutOption: GooglePayCheckoutOption?): PaymentRequest { - return PaymentRequest(applePayMerchantIdentifier, merchantName, totalLabel, countryCode, currencyCode, paymentItems, merchantCapabilities, supportedNetworks, shippingType, shippingMethods, billingContactRequired, shippingContactRequired, emailRequired, phoneNumberRequired, recurring, deferred, automaticReload, applePayMultiTokenContexts, couponCode, googlePayMerchantId, googlePayEnvironment, googlePayGateway, googlePayGatewayMerchantId, googlePayAllowedAuthMethods, googlePayAllowPrepaidCards, googlePayCheckoutOption) + private fun fromCpp(applePayMerchantIdentifier: String?, merchantName: String?, totalLabel: String?, countryCode: String, currencyCode: String, paymentItems: Array, merchantCapabilities: Array, supportedNetworks: Array, shippingType: String?, shippingMethods: Array?, billingContactRequired: Boolean?, shippingContactRequired: Boolean?, emailRequired: Boolean?, phoneNumberRequired: Boolean?, recurring: RecurringPaymentRequest?, deferred: DeferredPaymentRequest?, automaticReload: AutomaticReloadPaymentRequest?, applePayMultiTokenContexts: Array?, couponCode: String?, applePayMerchantCategoryCode: Double?, applePayLaterAvailability: String?, googlePayMerchantId: String?, googlePayEnvironment: GooglePayEnvironment?, googlePayGateway: String?, googlePayGatewayMerchantId: String?, googlePayAllowedAuthMethods: Array?, googlePayAllowPrepaidCards: Boolean?, googlePayCheckoutOption: GooglePayCheckoutOption?): PaymentRequest { + return PaymentRequest(applePayMerchantIdentifier, merchantName, totalLabel, countryCode, currencyCode, paymentItems, merchantCapabilities, supportedNetworks, shippingType, shippingMethods, billingContactRequired, shippingContactRequired, emailRequired, phoneNumberRequired, recurring, deferred, automaticReload, applePayMultiTokenContexts, couponCode, applePayMerchantCategoryCode, applePayLaterAvailability, googlePayMerchantId, googlePayEnvironment, googlePayGateway, googlePayGatewayMerchantId, googlePayAllowedAuthMethods, googlePayAllowPrepaidCards, googlePayCheckoutOption) } } } diff --git a/package/nitrogen/generated/ios/swift/PaymentRequest.swift b/package/nitrogen/generated/ios/swift/PaymentRequest.swift index 1933c94..49b9ccb 100644 --- a/package/nitrogen/generated/ios/swift/PaymentRequest.swift +++ b/package/nitrogen/generated/ios/swift/PaymentRequest.swift @@ -18,7 +18,7 @@ public extension PaymentRequest { /** * Create a new instance of `PaymentRequest`. */ - init(applePayMerchantIdentifier: String?, merchantName: String?, totalLabel: String?, countryCode: String, currencyCode: String, paymentItems: [PaymentItem], merchantCapabilities: [String], supportedNetworks: [String], shippingType: String?, shippingMethods: [ShippingMethod]?, billingContactRequired: Bool?, shippingContactRequired: Bool?, emailRequired: Bool?, phoneNumberRequired: Bool?, recurring: RecurringPaymentRequest?, deferred: DeferredPaymentRequest?, automaticReload: AutomaticReloadPaymentRequest?, applePayMultiTokenContexts: [PaymentTokenContext]?, couponCode: String?, googlePayMerchantId: String?, googlePayEnvironment: GooglePayEnvironment?, googlePayGateway: String?, googlePayGatewayMerchantId: String?, googlePayAllowedAuthMethods: [String]?, googlePayAllowPrepaidCards: Bool?, googlePayCheckoutOption: GooglePayCheckoutOption?) { + init(applePayMerchantIdentifier: String?, merchantName: String?, totalLabel: String?, countryCode: String, currencyCode: String, paymentItems: [PaymentItem], merchantCapabilities: [String], supportedNetworks: [String], shippingType: String?, shippingMethods: [ShippingMethod]?, billingContactRequired: Bool?, shippingContactRequired: Bool?, emailRequired: Bool?, phoneNumberRequired: Bool?, recurring: RecurringPaymentRequest?, deferred: DeferredPaymentRequest?, automaticReload: AutomaticReloadPaymentRequest?, applePayMultiTokenContexts: [PaymentTokenContext]?, couponCode: String?, applePayMerchantCategoryCode: Double?, applePayLaterAvailability: String?, googlePayMerchantId: String?, googlePayEnvironment: GooglePayEnvironment?, googlePayGateway: String?, googlePayGatewayMerchantId: String?, googlePayAllowedAuthMethods: [String]?, googlePayAllowPrepaidCards: Bool?, googlePayCheckoutOption: GooglePayCheckoutOption?) { self.init({ () -> bridge.std__optional_std__string_ in if let __unwrappedValue = applePayMerchantIdentifier { return bridge.create_std__optional_std__string_(std.string(__unwrappedValue)) @@ -133,6 +133,18 @@ public extension PaymentRequest { } else { return .init() } + }(), { () -> bridge.std__optional_double_ in + if let __unwrappedValue = applePayMerchantCategoryCode { + return bridge.create_std__optional_double_(__unwrappedValue) + } else { + return .init() + } + }(), { () -> bridge.std__optional_std__string_ in + if let __unwrappedValue = applePayLaterAvailability { + return bridge.create_std__optional_std__string_(std.string(__unwrappedValue)) + } else { + return .init() + } }(), { () -> bridge.std__optional_std__string_ in if let __unwrappedValue = googlePayMerchantId { return bridge.create_std__optional_std__string_(std.string(__unwrappedValue)) @@ -356,6 +368,30 @@ public extension PaymentRequest { }() } + @inline(__always) + var applePayMerchantCategoryCode: Double? { + return { () -> Double? in + if bridge.has_value_std__optional_double_(self.__applePayMerchantCategoryCode) { + let __unwrapped = bridge.get_std__optional_double_(self.__applePayMerchantCategoryCode) + return __unwrapped + } else { + return nil + } + }() + } + + @inline(__always) + var applePayLaterAvailability: String? { + return { () -> String? in + if bridge.has_value_std__optional_std__string_(self.__applePayLaterAvailability) { + let __unwrapped = bridge.get_std__optional_std__string_(self.__applePayLaterAvailability) + return String(__unwrapped) + } else { + return nil + } + }() + } + @inline(__always) var googlePayMerchantId: String? { return { () -> String? in diff --git a/package/nitrogen/generated/shared/c++/PaymentRequest.hpp b/package/nitrogen/generated/shared/c++/PaymentRequest.hpp index fe5a34d..03b22db 100644 --- a/package/nitrogen/generated/shared/c++/PaymentRequest.hpp +++ b/package/nitrogen/generated/shared/c++/PaymentRequest.hpp @@ -83,6 +83,8 @@ namespace margelo::nitro::pay { std::optional automaticReload SWIFT_PRIVATE; std::optional> applePayMultiTokenContexts SWIFT_PRIVATE; std::optional couponCode SWIFT_PRIVATE; + std::optional applePayMerchantCategoryCode SWIFT_PRIVATE; + std::optional applePayLaterAvailability SWIFT_PRIVATE; std::optional googlePayMerchantId SWIFT_PRIVATE; std::optional googlePayEnvironment SWIFT_PRIVATE; std::optional googlePayGateway SWIFT_PRIVATE; @@ -93,7 +95,7 @@ namespace margelo::nitro::pay { public: PaymentRequest() = default; - explicit PaymentRequest(std::optional applePayMerchantIdentifier, std::optional merchantName, std::optional totalLabel, std::string countryCode, std::string currencyCode, std::vector paymentItems, std::vector merchantCapabilities, std::vector supportedNetworks, std::optional shippingType, std::optional> shippingMethods, std::optional billingContactRequired, std::optional shippingContactRequired, std::optional emailRequired, std::optional phoneNumberRequired, std::optional recurring, std::optional deferred, std::optional automaticReload, std::optional> applePayMultiTokenContexts, std::optional couponCode, std::optional googlePayMerchantId, std::optional googlePayEnvironment, std::optional googlePayGateway, std::optional googlePayGatewayMerchantId, std::optional> googlePayAllowedAuthMethods, std::optional googlePayAllowPrepaidCards, std::optional googlePayCheckoutOption): applePayMerchantIdentifier(applePayMerchantIdentifier), merchantName(merchantName), totalLabel(totalLabel), countryCode(countryCode), currencyCode(currencyCode), paymentItems(paymentItems), merchantCapabilities(merchantCapabilities), supportedNetworks(supportedNetworks), shippingType(shippingType), shippingMethods(shippingMethods), billingContactRequired(billingContactRequired), shippingContactRequired(shippingContactRequired), emailRequired(emailRequired), phoneNumberRequired(phoneNumberRequired), recurring(recurring), deferred(deferred), automaticReload(automaticReload), applePayMultiTokenContexts(applePayMultiTokenContexts), couponCode(couponCode), googlePayMerchantId(googlePayMerchantId), googlePayEnvironment(googlePayEnvironment), googlePayGateway(googlePayGateway), googlePayGatewayMerchantId(googlePayGatewayMerchantId), googlePayAllowedAuthMethods(googlePayAllowedAuthMethods), googlePayAllowPrepaidCards(googlePayAllowPrepaidCards), googlePayCheckoutOption(googlePayCheckoutOption) {} + explicit PaymentRequest(std::optional applePayMerchantIdentifier, std::optional merchantName, std::optional totalLabel, std::string countryCode, std::string currencyCode, std::vector paymentItems, std::vector merchantCapabilities, std::vector supportedNetworks, std::optional shippingType, std::optional> shippingMethods, std::optional billingContactRequired, std::optional shippingContactRequired, std::optional emailRequired, std::optional phoneNumberRequired, std::optional recurring, std::optional deferred, std::optional automaticReload, std::optional> applePayMultiTokenContexts, std::optional couponCode, std::optional applePayMerchantCategoryCode, std::optional applePayLaterAvailability, std::optional googlePayMerchantId, std::optional googlePayEnvironment, std::optional googlePayGateway, std::optional googlePayGatewayMerchantId, std::optional> googlePayAllowedAuthMethods, std::optional googlePayAllowPrepaidCards, std::optional googlePayCheckoutOption): applePayMerchantIdentifier(applePayMerchantIdentifier), merchantName(merchantName), totalLabel(totalLabel), countryCode(countryCode), currencyCode(currencyCode), paymentItems(paymentItems), merchantCapabilities(merchantCapabilities), supportedNetworks(supportedNetworks), shippingType(shippingType), shippingMethods(shippingMethods), billingContactRequired(billingContactRequired), shippingContactRequired(shippingContactRequired), emailRequired(emailRequired), phoneNumberRequired(phoneNumberRequired), recurring(recurring), deferred(deferred), automaticReload(automaticReload), applePayMultiTokenContexts(applePayMultiTokenContexts), couponCode(couponCode), applePayMerchantCategoryCode(applePayMerchantCategoryCode), applePayLaterAvailability(applePayLaterAvailability), googlePayMerchantId(googlePayMerchantId), googlePayEnvironment(googlePayEnvironment), googlePayGateway(googlePayGateway), googlePayGatewayMerchantId(googlePayGatewayMerchantId), googlePayAllowedAuthMethods(googlePayAllowedAuthMethods), googlePayAllowPrepaidCards(googlePayAllowPrepaidCards), googlePayCheckoutOption(googlePayCheckoutOption) {} public: friend bool operator==(const PaymentRequest& lhs, const PaymentRequest& rhs) = default; @@ -128,6 +130,8 @@ namespace margelo::nitro { JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "automaticReload"))), JSIConverter>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "applePayMultiTokenContexts"))), JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "couponCode"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "applePayMerchantCategoryCode"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "applePayLaterAvailability"))), JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "googlePayMerchantId"))), JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "googlePayEnvironment"))), JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "googlePayGateway"))), @@ -158,6 +162,8 @@ namespace margelo::nitro { obj.setProperty(runtime, PropNameIDCache::get(runtime, "automaticReload"), JSIConverter>::toJSI(runtime, arg.automaticReload)); obj.setProperty(runtime, PropNameIDCache::get(runtime, "applePayMultiTokenContexts"), JSIConverter>>::toJSI(runtime, arg.applePayMultiTokenContexts)); obj.setProperty(runtime, PropNameIDCache::get(runtime, "couponCode"), JSIConverter>::toJSI(runtime, arg.couponCode)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "applePayMerchantCategoryCode"), JSIConverter>::toJSI(runtime, arg.applePayMerchantCategoryCode)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "applePayLaterAvailability"), JSIConverter>::toJSI(runtime, arg.applePayLaterAvailability)); obj.setProperty(runtime, PropNameIDCache::get(runtime, "googlePayMerchantId"), JSIConverter>::toJSI(runtime, arg.googlePayMerchantId)); obj.setProperty(runtime, PropNameIDCache::get(runtime, "googlePayEnvironment"), JSIConverter>::toJSI(runtime, arg.googlePayEnvironment)); obj.setProperty(runtime, PropNameIDCache::get(runtime, "googlePayGateway"), JSIConverter>::toJSI(runtime, arg.googlePayGateway)); @@ -194,6 +200,8 @@ namespace margelo::nitro { if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "automaticReload")))) return false; if (!JSIConverter>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "applePayMultiTokenContexts")))) return false; if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "couponCode")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "applePayMerchantCategoryCode")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "applePayLaterAvailability")))) return false; if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "googlePayMerchantId")))) return false; if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "googlePayEnvironment")))) return false; if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "googlePayGateway")))) return false; diff --git a/package/src/types/Payment.ts b/package/src/types/Payment.ts index c2118a9..3ff3250 100644 --- a/package/src/types/Payment.ts +++ b/package/src/types/Payment.ts @@ -127,6 +127,15 @@ export type ShippingType = | 'storePickup' | 'servicePickup' +/** + * Whether the payer may pay with Apple Pay Later, and if not, why. The sheet + * tells the payer the reason. iOS only. + */ +export type ApplePayLaterAvailability = + | 'available' + | 'itemIneligible' + | 'recurringTransaction' + export interface PKPass { passTypeIdentifier: string serialNumber: string @@ -438,6 +447,22 @@ export interface PaymentRequest { * `'CONFIGURATION'`. iOS only; Android ignores it. */ couponCode?: string + /** + * The merchant's ISO 18245 category code, from 0 to 9999, for example + * `5411` for grocery stores. Apple Pay leaves out the cards that don't + * accept the category. iOS 18 and later; earlier versions ignore it. + * Another value, including a fraction, fails the payment with + * `'CONFIGURATION'` on any iOS version. iOS only; Android ignores it. + */ + applePayMerchantCategoryCode?: number + /** + * An `ApplePayLaterAvailability` value. Hides Apple Pay Later and tells + * the payer why, for example for gift cards, which must not be paid over + * time. iOS 17 and later; earlier versions ignore it. An unknown value + * fails the payment on iOS. Not typed as `ApplePayLaterAvailability` for + * the same reason as `merchantCapabilities`. iOS only; Android ignores it. + */ + applePayLaterAvailability?: string // Google Pay specific configuration (Android only) googlePayMerchantId?: string googlePayEnvironment?: GooglePayEnvironment