Skip to content

Commit 104d39d

Browse files
authored
Merge pull request #1496 from braintree/shipping-callback-feature
[DO NOT REVIEW] Merge Shipping Callback Feature Branch
2 parents aa9f71a + 37782b4 commit 104d39d

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## unreleased
44
* BraintreePayPal
55
* Fix bug to ensure that `BTPayPalVaultRequest.userAuthenticationEmail` is not sent as an empty string
6+
* Add `shippingCallbackURL` to `BTPayPalCheckoutRequest`
67
* BraintreeThreeDSecure
78
* Return error if no `dfReferenceId` is returned in the 3D Secure flow
89

Sources/BraintreePayPal/BTPayPalCheckoutRequest.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ import BraintreeCore
8585
/// Optional: User email to initiate a quicker authentication flow in cases where the user has a PayPal Account with the same email.
8686
public var userAuthenticationEmail: String?
8787

88+
/// 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.
89+
public var shippingCallbackURL: URL?
90+
8891
// MARK: - Initializer
8992

9093
/// Initializes a PayPal Native Checkout request
@@ -98,20 +101,24 @@ import BraintreeCore
98101
/// See https://developer.paypal.com/docs/api/reference/currency-codes/ for a list of supported currency codes.
99102
/// - 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
100103
/// during checkout. Defaults to `false`.
104+
/// - shippingCallbackURL: Optional: Server side shipping callback URL to be notified when a customer updates their shipping address or options.
105+
/// A callback request will be sent to the merchant server at this URL.
101106
public init(
102107
amount: String,
103108
intent: BTPayPalRequestIntent = .authorize,
104109
userAction: BTPayPalRequestUserAction = .none,
105110
offerPayLater: Bool = false,
106111
currencyCode: String? = nil,
107-
requestBillingAgreement: Bool = false
112+
requestBillingAgreement: Bool = false,
113+
shippingCallbackURL: URL? = nil
108114
) {
109115
self.amount = amount
110116
self.intent = intent
111117
self.userAction = userAction
112118
self.offerPayLater = offerPayLater
113119
self.currencyCode = currencyCode
114120
self.requestBillingAgreement = requestBillingAgreement
121+
self.shippingCallbackURL = shippingCallbackURL
115122

116123
super.init(hermesPath: "v1/paypal_hermes/create_payment_resource", paymentType: .checkout)
117124
}
@@ -155,6 +162,10 @@ import BraintreeCore
155162
}
156163
}
157164

165+
if let shippingCallbackURL {
166+
baseParameters["shipping_callback_url"] = shippingCallbackURL.absoluteString
167+
}
168+
158169
if shippingAddressOverride != nil {
159170
checkoutParameters["line1"] = shippingAddressOverride?.streetAddress
160171
checkoutParameters["line2"] = shippingAddressOverride?.extendedAddress

UnitTests/BraintreePayPalTests/BTPayPalCheckoutRequest_Tests.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,20 @@ class BTPayPalCheckoutRequest_Tests: XCTestCase {
176176

177177
XCTAssertNil(parameters["payer_email"])
178178
}
179+
180+
func testParameters_whenShippingCallbackURLNotSet_returnsParameters() {
181+
let request = BTPayPalCheckoutRequest(amount: "1")
182+
183+
XCTAssertNil(request.shippingCallbackURL)
184+
let parameters = request.parameters(with: configuration)
185+
XCTAssertNil(parameters["shipping_callback_url"])
186+
}
187+
188+
func testParameters_whitShippingCallbackURL_returnsParametersWithShippingCallbackURL() {
189+
let request = BTPayPalCheckoutRequest(amount: "1", shippingCallbackURL: URL(string: "www.some-url.com"))
190+
191+
XCTAssertNotNil(request.shippingCallbackURL)
192+
let parameters = request.parameters(with: configuration)
193+
XCTAssertNotNil(parameters["shipping_callback_url"])
194+
}
179195
}

0 commit comments

Comments
 (0)