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 #1252

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Braintree Android SDK Release Notes

## unreleased

* PayPal
* Add `shippingCallbackURL` to `PayPalCheckoutRequest`
jaxdesmarais marked this conversation as resolved.
Show resolved Hide resolved

## 5.3.0 (2024-12-11)

* PayPal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.braintreepayments.api.paypal

import android.net.Uri
import android.text.TextUtils
import com.braintreepayments.api.core.Authorization
import com.braintreepayments.api.core.ClientToken
Expand Down Expand Up @@ -54,6 +55,9 @@ import org.json.JSONObject
*
* @property shouldOfferPayLater Offers PayPal Pay Later if the customer qualifies. Defaults to
* false.
* @property shippingCallbackUrl 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.
*/
@Parcelize
class PayPalCheckoutRequest @JvmOverloads constructor(
Expand All @@ -64,6 +68,7 @@ class PayPalCheckoutRequest @JvmOverloads constructor(
var currencyCode: String? = null,
var shouldRequestBillingAgreement: Boolean = false,
var shouldOfferPayLater: Boolean = false,
var shippingCallbackUrl: Uri? = null,
override var localeCode: String? = null,
override var billingAgreementDescription: String? = null,
override var isShippingAddressRequired: Boolean = false,
Expand All @@ -75,7 +80,7 @@ class PayPalCheckoutRequest @JvmOverloads constructor(
override var riskCorrelationId: String? = null,
override var userAuthenticationEmail: String? = null,
override var userPhoneNumber: PayPalPhoneNumber? = null,
override var lineItems: List<PayPalLineItem> = emptyList(),
override var lineItems: List<PayPalLineItem> = emptyList()
) : PayPalRequest(
hasUserLocationConsent = hasUserLocationConsent,
localeCode = localeCode,
Expand Down Expand Up @@ -105,6 +110,10 @@ class PayPalCheckoutRequest @JvmOverloads constructor(
.put(CANCEL_URL_KEY, cancelUrl)
.put(OFFER_PAY_LATER_KEY, shouldOfferPayLater)

shippingCallbackUrl?.let {
if (it.toString().isNotEmpty()) parameters.put(SHIPPING_CALLBACK_URL_KEY, it)
}

if (authorization is ClientToken) {
parameters.put(AUTHORIZATION_FINGERPRINT_KEY, authorization.bearer)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,6 @@ abstract class PayPalRequest internal constructor(
internal const val PLAN_TYPE_KEY: String = "plan_type"
internal const val PLAN_METADATA_KEY: String = "plan_metadata"
internal const val PHONE_NUMBER_KEY: String = "phone_number"
internal const val SHIPPING_CALLBACK_URL_KEY: String = "shipping_callback_url"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class PayPalVaultRequest
override var riskCorrelationId: String? = null,
override var userAuthenticationEmail: String? = null,
override var userPhoneNumber: PayPalPhoneNumber? = null,
override var lineItems: List<PayPalLineItem> = emptyList(),
override var lineItems: List<PayPalLineItem> = emptyList()
) : PayPalRequest(
hasUserLocationConsent = hasUserLocationConsent,
localeCode = localeCode,
Expand All @@ -62,7 +62,7 @@ class PayPalVaultRequest
merchantAccountId = merchantAccountId,
riskCorrelationId = riskCorrelationId,
userAuthenticationEmail = userAuthenticationEmail,
lineItems = lineItems
lineItems = lineItems,
) {

@Throws(JSONException::class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.braintreepayments.api.paypal;

import android.net.Uri;
import android.os.Parcel;

import com.braintreepayments.api.core.Authorization;
import com.braintreepayments.api.core.Configuration;
import com.braintreepayments.api.core.PostalAddress;

import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
Expand Down Expand Up @@ -157,6 +159,58 @@ public void createRequestBody_does_not_set_userAuthenticationEmail_when_email_is
}

@Test
public void createRequestBody_sets_shippingCallbackUri_when_not_null() throws JSONException {
String urlString = "https://www.example.com/path";
Uri uri = Uri.parse(urlString);

PayPalCheckoutRequest request = new PayPalCheckoutRequest("1.00", true);
request.setShippingCallbackUrl(uri);

String requestBody = request.createRequestBody(
mock(Configuration.class),
mock(Authorization.class),
"success_url",
"cancel_url",
null
);

JSONObject jsonObject = new JSONObject(requestBody);
assertEquals(urlString, jsonObject.getString("shipping_callback_url"));
}

@Test
public void createRequestBody_does_not_set_shippingCallbackUri_when_null() throws JSONException {
PayPalCheckoutRequest request = new PayPalCheckoutRequest("1.00", true);

String requestBody = request.createRequestBody(
mock(Configuration.class),
mock(Authorization.class),
"success_url",
"cancel_url",
null
);

JSONObject jsonObject = new JSONObject(requestBody);
assertFalse(jsonObject.has("shipping_callback_url"));
}

@Test
public void createRequestBody_does_not_set_shippingCallbackUri_when_empty() throws JSONException {
PayPalCheckoutRequest request = new PayPalCheckoutRequest("1.00", true);
request.setShippingCallbackUrl(Uri.parse(""));

String requestBody = request.createRequestBody(
mock(Configuration.class),
mock(Authorization.class),
"success_url",
"cancel_url",
null
);

JSONObject jsonObject = new JSONObject(requestBody);
assertFalse(jsonObject.has("shipping_callback_url"));
}

public void createRequestBody_sets_userPhoneNumber_when_not_null() throws JSONException {
PayPalCheckoutRequest request = new PayPalCheckoutRequest("1.00", true);

Expand All @@ -171,4 +225,5 @@ public void createRequestBody_sets_userPhoneNumber_when_not_null() throws JSONEx

assertTrue(requestBody.contains("\"phone_number\":{\"country_code\":\"1\",\"national_number\":\"1231231234\"}"));
}
}
}

Loading