Skip to content

Commit

Permalink
Merge pull request #1496 from braintree/shipping-callback-feature
Browse files Browse the repository at this point in the history
[DO NOT REVIEW] Merge Shipping Callback Feature Branch
  • Loading branch information
jaxdesmarais authored Jan 21, 2025
2 parents aa9f71a + 37782b4 commit 104d39d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## unreleased
* BraintreePayPal
* Fix bug to ensure that `BTPayPalVaultRequest.userAuthenticationEmail` is not sent as an empty string
* Add `shippingCallbackURL` to `BTPayPalCheckoutRequest`
* BraintreeThreeDSecure
* Return error if no `dfReferenceId` is returned in the 3D Secure flow

Expand Down
13 changes: 12 additions & 1 deletion Sources/BraintreePayPal/BTPayPalCheckoutRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -98,20 +101,24 @@ 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
self.userAction = userAction
self.offerPayLater = offerPayLater
self.currencyCode = currencyCode
self.requestBillingAgreement = requestBillingAgreement
self.shippingCallbackURL = shippingCallbackURL

super.init(hermesPath: "v1/paypal_hermes/create_payment_resource", paymentType: .checkout)
}
Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions UnitTests/BraintreePayPalTests/BTPayPalCheckoutRequest_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
}
}

0 comments on commit 104d39d

Please sign in to comment.