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

[DO NOT REVIEW] Merge Shipping Callback Feature Branch #1496

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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 @@

## 6.25.0 (2024-12-11)
* BraintreePayPal
* Add `shippingCallbackURL` to `BTPayPalCheckoutRequest`
Copy link
Contributor

Choose a reason for hiding this comment

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

Should move to unreleased section

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, great catch

* Add `BTPayPalRequest.userPhoneNumber` optional property
* Send `url` in `event_params` for App Switch events to PayPal's analytics service (FPTI)
* BraintreeVenmo
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
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"])
}
}