diff --git a/CHANGELOG.md b/CHANGELOG.md index 748b2edb8..80175b4eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Braintree iOS SDK Release Notes +## unreleased +* BraintreePayPal + * Add `shippingCallbackURL` to `BTPayPalCheckoutRequest` + ## 6.25.0 (2024-12-11) * BraintreePayPal * Add `BTPayPalRequest.userPhoneNumber` optional property diff --git a/Sources/BraintreePayPal/BTPayPalCheckoutRequest.swift b/Sources/BraintreePayPal/BTPayPalCheckoutRequest.swift index cec57840b..6d2378c5b 100644 --- a/Sources/BraintreePayPal/BTPayPalCheckoutRequest.swift +++ b/Sources/BraintreePayPal/BTPayPalCheckoutRequest.swift @@ -85,6 +85,9 @@ import BraintreeCore /// Optional: User email to initiate a quicker authentication flow in cases where the user has a PayPal Account with the same email. public var userAuthenticationEmail: String? + /// Optional: Server side shipping callback URL to be notified when a customer updates their shipping address or options. A callback request will be sent to the merchant server at this URL. + public var shippingCallbackURL: URL? + // MARK: - Initializer /// Initializes a PayPal Native Checkout request @@ -98,13 +101,16 @@ import BraintreeCore /// See https://developer.paypal.com/docs/api/reference/currency-codes/ for a list of supported currency codes. /// - requestBillingAgreement: Optional: If set to `true`, this enables the Checkout with Vault flow, where the customer will be prompted to consent to a billing agreement /// during checkout. Defaults to `false`. + /// - shippingCallbackURL: Optional: Server side shipping callback URL to be notified when a customer updates their shipping address or options. + /// A callback request will be sent to the merchant server at this URL. public init( amount: String, intent: BTPayPalRequestIntent = .authorize, userAction: BTPayPalRequestUserAction = .none, offerPayLater: Bool = false, currencyCode: String? = nil, - requestBillingAgreement: Bool = false + requestBillingAgreement: Bool = false, + shippingCallbackURL: URL? = nil ) { self.amount = amount self.intent = intent @@ -112,6 +118,7 @@ import BraintreeCore self.offerPayLater = offerPayLater self.currencyCode = currencyCode self.requestBillingAgreement = requestBillingAgreement + self.shippingCallbackURL = shippingCallbackURL super.init(hermesPath: "v1/paypal_hermes/create_payment_resource", paymentType: .checkout) } @@ -155,6 +162,10 @@ import BraintreeCore } } + if let shippingCallbackURL { + baseParameters["shipping_callback_url"] = shippingCallbackURL.absoluteString + } + if shippingAddressOverride != nil { checkoutParameters["line1"] = shippingAddressOverride?.streetAddress checkoutParameters["line2"] = shippingAddressOverride?.extendedAddress diff --git a/UnitTests/BraintreePayPalTests/BTPayPalCheckoutRequest_Tests.swift b/UnitTests/BraintreePayPalTests/BTPayPalCheckoutRequest_Tests.swift index e082e120f..4a94111ef 100644 --- a/UnitTests/BraintreePayPalTests/BTPayPalCheckoutRequest_Tests.swift +++ b/UnitTests/BraintreePayPalTests/BTPayPalCheckoutRequest_Tests.swift @@ -176,4 +176,20 @@ class BTPayPalCheckoutRequest_Tests: XCTestCase { XCTAssertNil(parameters["payer_email"]) } + + func testParameters_whenShippingCallbackURLNotSet_returnsParameters() { + let request = BTPayPalCheckoutRequest(amount: "1") + + XCTAssertNil(request.shippingCallbackURL) + let parameters = request.parameters(with: configuration) + XCTAssertNil(parameters["shipping_callback_url"]) + } + + func testParameters_whitShippingCallbackURL_returnsParametersWithShippingCallbackURL() { + let request = BTPayPalCheckoutRequest(amount: "1", shippingCallbackURL: URL(string: "www.some-url.com")) + + XCTAssertNotNil(request.shippingCallbackURL) + let parameters = request.parameters(with: configuration) + XCTAssertNotNil(parameters["shipping_callback_url"]) + } }