From 60b7fbddb5d6df30f4d34e5050c579293dc9463b Mon Sep 17 00:00:00 2001 From: AhlaamK-tap Date: Sun, 16 Oct 2022 15:53:49 +0300 Subject: [PATCH] NPE Check --- .../internal/activities/GoSellPaymentActivity.java | 5 ++++- .../tap/gosellapi/internal/utils/PaymentsUtil.java | 4 ++++ .../viewholders/GooglePaymentViewHolder.java | 13 ++++++++----- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/library/src/main/java/company/tap/gosellapi/internal/activities/GoSellPaymentActivity.java b/library/src/main/java/company/tap/gosellapi/internal/activities/GoSellPaymentActivity.java index d796a53f..89a38eb9 100644 --- a/library/src/main/java/company/tap/gosellapi/internal/activities/GoSellPaymentActivity.java +++ b/library/src/main/java/company/tap/gosellapi/internal/activities/GoSellPaymentActivity.java @@ -156,7 +156,10 @@ protected void onCreate(Bundle savedInstanceState) { overridePendingTransition(R.anim.slide_in_top, android.R.anim.fade_out); if(PaymentDataSource.getInstance().getTransactionMode() == TransactionMode.PURCHASE){ paymentsClient = PaymentsUtil.createPaymentsClient(this); - possiblyShowGooglePayButton(); + if(PaymentDataSource.getInstance().getGooglePaymentOptions().size()!=0){ + possiblyShowGooglePayButton(); + } + } apperanceMode = ThemeObject.getInstance().getAppearanceMode(); diff --git a/library/src/main/java/company/tap/gosellapi/internal/utils/PaymentsUtil.java b/library/src/main/java/company/tap/gosellapi/internal/utils/PaymentsUtil.java index 4f3e92f4..8d0bce8a 100644 --- a/library/src/main/java/company/tap/gosellapi/internal/utils/PaymentsUtil.java +++ b/library/src/main/java/company/tap/gosellapi/internal/utils/PaymentsUtil.java @@ -56,7 +56,9 @@ public class PaymentsUtil { * @throws JSONException */ private static JSONObject getBaseRequest() throws JSONException { + if(PaymentDataSource.getInstance().getGooglePaymentOptions().size() != 0){ return new JSONObject().put("apiVersion", PaymentDataSource.getInstance().getGooglePaymentOptions().get(0).getApiVersion()).put("apiVersionMinor", PaymentDataSource.getInstance().getGooglePaymentOptions().get(0).getApiVersionMinor()); + }else return null; } /** @@ -186,6 +188,7 @@ private static JSONObject getBaseCardPaymentMethod() throws JSONException { cardPaymentMethod.put("type", "CARD"); // System.out.println("Payment data"+PaymentDataSource.getInstance().getGooglePaymentOptions().get(0).getSupportedCardBrands()); JSONObject parameters = new JSONObject(); + if(PaymentDataSource.getInstance().getGooglePaymentOptions().size() != 0) parameters.put("allowedAuthMethods", new JSONArray(PaymentDataSource.getInstance().getGooglePaymentOptions().get(0).getAllowed_auth_methods())); // parameters.put("allowedAuthMethods", getAllowedCardAuthMethods()); // parameters.put("allowedCardNetworks", getAllowedCardNetworks()); @@ -235,6 +238,7 @@ public static Optional getIsReadyToPayRequest() { isReadyToPayRequest.put( "allowedPaymentMethods", new JSONArray().put(getBaseCardPaymentMethod())); + return Optional.of(isReadyToPayRequest); } catch (JSONException e) { diff --git a/library/src/main/java/company/tap/gosellapi/internal/viewholders/GooglePaymentViewHolder.java b/library/src/main/java/company/tap/gosellapi/internal/viewholders/GooglePaymentViewHolder.java index 8f27527e..ae960437 100644 --- a/library/src/main/java/company/tap/gosellapi/internal/viewholders/GooglePaymentViewHolder.java +++ b/library/src/main/java/company/tap/gosellapi/internal/viewholders/GooglePaymentViewHolder.java @@ -64,11 +64,14 @@ public class GooglePaymentViewHolder extends PaymentOptionsBaseViewHolder requestPayment(view1) + if(PaymentDataSource.getInstance().getGooglePaymentOptions().size()!=0){ + possiblyShowGooglePayButton(); + googlePayButton.setOnClickListener( + view1 -> requestPayment(view1) + + ); + } - ); } @@ -131,7 +134,7 @@ private void requestPayment(View view) { } PaymentDataRequest request = PaymentDataRequest.fromJson(paymentDataRequestJson.get().toString()); - // System.out.println("request value is>>>"+request.toJson()); + System.out.println("request value is>>>"+request.toJson()); // Since loadPaymentData may show the UI asking the user to select a payment method, we use // AutoResolveHelper to wait for the user interacting with it. Once completed,