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

Move Shipping Callback URL to PayPalCheckoutRequest #1200

Merged
merged 6 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
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)
}
Comment on lines -85 to -87
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this logic move into PayPalCheckoutRequest?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Logic is already there

thanks for asking

My mistake was approaching this change differently in iOS. In iOS, I created the feature branch from scratch, while here, I only removed shippingCallbackUrl from the Vault flow, keeping the changes from the PR previously merged into this feature branch.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah gotcha, no worries! Thanks for pointing out where it was since the approach was slightly different.


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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we able to add these tests to PayPalCheckoutRequestUnitTest?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, there are already 3 unit tests that cover this in PayPalCheckoutRequestUnitTest

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"));
}
}
Loading