Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Shipping Callback URL to BTPayPalCheckoutRequest #1451

Merged
merged 3 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## unreleased
* BraintreePayPal
* Add `shippingCallbackURL` to `BTPayPalCheckoutRequest`
* Add `BTPayPalRequest.userPhoneNumber` optional property
* BraintreeVenmo
* Send `url` in `event_params` for App Switch events to PayPal's analytics service (FPTI)
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit - does this line 105 appear under the shippingCallbackURL param docstring? Or since it's a newline it might appear in the general function description. (I'm admin-ed out of Xcode right now or else I'd check the preview)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦅 👁️ yeah, I wondered the same thing. The docstrings are a bit peculiar, i checked earlier, and this is how they look. What do you think?

Screenshot 2024-10-31 at 1 40 47 p m

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

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
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"])
}
}