@Test public void testHandleGooglePayResultCallsCancelled() { int requestCode = Gateway.REQUEST_GOOGLE_PAY_LOAD_PAYMENT_DATA; int resultCode = Activity.RESULT_CANCELED; GatewayGooglePayCallback callback = mock(GatewayGooglePayCallback.class); boolean result = Gateway.handleGooglePayResult(requestCode, resultCode, null, callback); assertTrue(result); verify(callback).onGooglePayCancelled(); }
public static boolean handleGooglePayResult(int requestCode, int resultCode, Intent data, GatewayGooglePayCallback callback) { if (callback == null) { return false; } if (requestCode == REQUEST_GOOGLE_PAY_LOAD_PAYMENT_DATA) { if (resultCode == Activity.RESULT_OK) { try { PaymentData paymentData = PaymentData.getFromIntent(data); JSONObject json = new JSONObject(paymentData.toJson()); callback.onReceivedPaymentData(json); } catch (Exception e) { callback.onGooglePayError(Status.RESULT_INTERNAL_ERROR); } } else if (resultCode == Activity.RESULT_CANCELED) { callback.onGooglePayCancelled(); } else if (resultCode == AutoResolveHelper.RESULT_ERROR) { Status status = AutoResolveHelper.getStatusFromIntent(data); callback.onGooglePayError(status); } return true; } return false; }
Gateway { public static boolean handleGooglePayResult(int requestCode, int resultCode, Intent data, GatewayGooglePayCallback callback) { if (callback == null) { return false; } if (requestCode == REQUEST_GOOGLE_PAY_LOAD_PAYMENT_DATA) { if (resultCode == Activity.RESULT_OK) { try { PaymentData paymentData = PaymentData.getFromIntent(data); JSONObject json = new JSONObject(paymentData.toJson()); callback.onReceivedPaymentData(json); } catch (Exception e) { callback.onGooglePayError(Status.RESULT_INTERNAL_ERROR); } } else if (resultCode == Activity.RESULT_CANCELED) { callback.onGooglePayCancelled(); } else if (resultCode == AutoResolveHelper.RESULT_ERROR) { Status status = AutoResolveHelper.getStatusFromIntent(data); callback.onGooglePayError(status); } return true; } return false; } }
Gateway { public static boolean handleGooglePayResult(int requestCode, int resultCode, Intent data, GatewayGooglePayCallback callback) { if (callback == null) { return false; } if (requestCode == REQUEST_GOOGLE_PAY_LOAD_PAYMENT_DATA) { if (resultCode == Activity.RESULT_OK) { try { PaymentData paymentData = PaymentData.getFromIntent(data); JSONObject json = new JSONObject(paymentData.toJson()); callback.onReceivedPaymentData(json); } catch (Exception e) { callback.onGooglePayError(Status.RESULT_INTERNAL_ERROR); } } else if (resultCode == Activity.RESULT_CANCELED) { callback.onGooglePayCancelled(); } else if (resultCode == AutoResolveHelper.RESULT_ERROR) { Status status = AutoResolveHelper.getStatusFromIntent(data); callback.onGooglePayError(status); } return true; } return false; } Gateway(); }
Gateway { public static boolean handleGooglePayResult(int requestCode, int resultCode, Intent data, GatewayGooglePayCallback callback) { if (callback == null) { return false; } if (requestCode == REQUEST_GOOGLE_PAY_LOAD_PAYMENT_DATA) { if (resultCode == Activity.RESULT_OK) { try { PaymentData paymentData = PaymentData.getFromIntent(data); JSONObject json = new JSONObject(paymentData.toJson()); callback.onReceivedPaymentData(json); } catch (Exception e) { callback.onGooglePayError(Status.RESULT_INTERNAL_ERROR); } } else if (resultCode == Activity.RESULT_CANCELED) { callback.onGooglePayCancelled(); } else if (resultCode == AutoResolveHelper.RESULT_ERROR) { Status status = AutoResolveHelper.getStatusFromIntent(data); callback.onGooglePayError(status); } return true; } return false; } Gateway(); String getMerchantId(); Gateway setMerchantId(String merchantId); Region getRegion(); Gateway setRegion(Region region); void updateSession(String sessionId, String apiVersion, GatewayMap payload, GatewayCallback callback); Single<GatewayMap> updateSession(String sessionId, String apiVersion, GatewayMap payload); static void start3DSecureActivity(Activity activity, String html); static void start3DSecureActivity(Activity activity, String html, String title); static boolean handle3DSecureResult(int requestCode, int resultCode, Intent data, Gateway3DSecureCallback callback); static void requestGooglePayData(PaymentsClient paymentsClient, PaymentDataRequest request, Activity activity); static boolean handleGooglePayResult(int requestCode, int resultCode, Intent data, GatewayGooglePayCallback callback); }
Gateway { public static boolean handleGooglePayResult(int requestCode, int resultCode, Intent data, GatewayGooglePayCallback callback) { if (callback == null) { return false; } if (requestCode == REQUEST_GOOGLE_PAY_LOAD_PAYMENT_DATA) { if (resultCode == Activity.RESULT_OK) { try { PaymentData paymentData = PaymentData.getFromIntent(data); JSONObject json = new JSONObject(paymentData.toJson()); callback.onReceivedPaymentData(json); } catch (Exception e) { callback.onGooglePayError(Status.RESULT_INTERNAL_ERROR); } } else if (resultCode == Activity.RESULT_CANCELED) { callback.onGooglePayCancelled(); } else if (resultCode == AutoResolveHelper.RESULT_ERROR) { Status status = AutoResolveHelper.getStatusFromIntent(data); callback.onGooglePayError(status); } return true; } return false; } Gateway(); String getMerchantId(); Gateway setMerchantId(String merchantId); Region getRegion(); Gateway setRegion(Region region); void updateSession(String sessionId, String apiVersion, GatewayMap payload, GatewayCallback callback); Single<GatewayMap> updateSession(String sessionId, String apiVersion, GatewayMap payload); static void start3DSecureActivity(Activity activity, String html); static void start3DSecureActivity(Activity activity, String html, String title); static boolean handle3DSecureResult(int requestCode, int resultCode, Intent data, Gateway3DSecureCallback callback); static void requestGooglePayData(PaymentsClient paymentsClient, PaymentDataRequest request, Activity activity); static boolean handleGooglePayResult(int requestCode, int resultCode, Intent data, GatewayGooglePayCallback callback);  }