Skip to content

Commit

Permalink
Move Shipping Callback URL to PayPalCheckoutRequest (#1200)
Browse files Browse the repository at this point in the history
* Remove unnecessary Vault UTs

* Update CHANGELOG

* Remove shippingCallbackUrl from PayPalRequest interface

* Remove shippingCallbackUri from PayPalVaultRequest class

* Remove unnecessary docstring from interface

* Make shippingCallbackUrl a property of PayPalCheckoutRequest
  • Loading branch information
richherrera authored Nov 1, 2024
1 parent 4188670 commit 182f599
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 74 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## unreleased

* PayPal
* Add `shippingCallbackURL` to `PayPalRequest`
* Add `shippingCallbackURL` to `PayPalCheckoutRequest`

## 5.2.0 (2024-10-30)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,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 @@ -65,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 @@ -76,8 +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 shippingCallbackUrl: Uri? = null,
override var lineItems: List<PayPalLineItem> = emptyList()
) : PayPalRequest(
hasUserLocationConsent = hasUserLocationConsent,
localeCode = localeCode,
Expand All @@ -90,8 +93,7 @@ class PayPalCheckoutRequest @JvmOverloads constructor(
merchantAccountId = merchantAccountId,
riskCorrelationId = riskCorrelationId,
userAuthenticationEmail = userAuthenticationEmail,
lineItems = lineItems,
shippingCallbackUrl = shippingCallbackUrl,
lineItems = lineItems
) {

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

import android.net.Uri
import android.os.Parcelable
import androidx.annotation.RestrictTo
import com.braintreepayments.api.core.Authorization
Expand Down Expand Up @@ -74,9 +73,6 @@ import org.json.JSONException
* @property userPhoneNumber User phone number used to initiate a quicker authentication flow in
* cases where the user has a PayPal Account with the phone number.
* @property lineItems The line items for this transaction. It can include up to 249 line items.
* @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.
*/
abstract class PayPalRequest internal constructor(
open val hasUserLocationConsent: Boolean,
Expand All @@ -91,8 +87,7 @@ abstract class PayPalRequest internal constructor(
open var riskCorrelationId: String? = null,
open var userAuthenticationEmail: String? = null,
open var userPhoneNumber: PayPalPhoneNumber? = null,
open var lineItems: List<PayPalLineItem> = emptyList(),
open var shippingCallbackUrl: Uri? = null
open var lineItems: List<PayPalLineItem> = emptyList()
) : Parcelable {

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

import android.net.Uri
import android.os.Build
import android.text.TextUtils
import com.braintreepayments.api.core.Authorization
Expand Down Expand Up @@ -50,8 +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 shippingCallbackUrl: Uri? = null,
override var lineItems: List<PayPalLineItem> = emptyList()
) : PayPalRequest(
hasUserLocationConsent = hasUserLocationConsent,
localeCode = localeCode,
Expand All @@ -65,7 +63,6 @@ class PayPalVaultRequest
riskCorrelationId = riskCorrelationId,
userAuthenticationEmail = userAuthenticationEmail,
lineItems = lineItems,
shippingCallbackUrl = shippingCallbackUrl,
) {

@Throws(JSONException::class)
Expand All @@ -82,10 +79,6 @@ class PayPalVaultRequest
.put(CANCEL_URL_KEY, cancelUrl)
.put(OFFER_CREDIT_KEY, shouldOfferCredit)

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 @@ -7,7 +7,6 @@
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;

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

Expand All @@ -17,7 +16,6 @@
import com.braintreepayments.api.testutils.Fixtures;

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 @@ -301,57 +299,4 @@ public void createRequestBody_sets_userPhoneNumber_when_not_null() throws JSONEx

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

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

PayPalVaultRequest request = new PayPalVaultRequest(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 {
PayPalVaultRequest request = new PayPalVaultRequest(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 {
PayPalVaultRequest request = new PayPalVaultRequest(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"));
}
}

0 comments on commit 182f599

Please sign in to comment.