/** * Create the parameters necessary for confirming a PaymentIntent while attaching a source that * already exits. * * @param sourceId the ID of the source that is being attached to the PaymentIntent being * confirmed * @param clientSecret client secret from the PaymentIntent being confirmed * @param returnUrl the URL the customer should be redirected to after the authorization * process * @return params that can be use to confirm a PaymentIntent */ @NonNull public static PaymentIntentParams createConfirmPaymentIntentWithSourceIdParams( @Nullable String sourceId, @NonNull String clientSecret, @Nullable String returnUrl) { return new PaymentIntentParams() .setSourceId(sourceId) .setClientSecret(clientSecret) .setReturnUrl(returnUrl); }
/** * Create the parameters necessary for retrieving the details of PaymentIntent * * @param clientSecret client secret from the PaymentIntent that is being retrieved * @return params that can be used to retrieve a PaymentIntent */ @NonNull public static PaymentIntentParams createRetrievePaymentIntentParams( @NonNull String clientSecret) { return new PaymentIntentParams().setClientSecret(clientSecret); }
/** * Create the parameters necessary for confirming a PaymentIntent while attaching Source data * * @param sourceParams params for the source that will be attached to this payment intent * @param clientSecret client secret from the PaymentIntent that is to be confirmed * @param returnUrl the URL the customer should be redirected to after the authorization * process * @return params that can be use to confirm a PaymentIntent */ @NonNull public static PaymentIntentParams createConfirmPaymentIntentWithSourceDataParams( @Nullable SourceParams sourceParams, @NonNull String clientSecret, @Nullable String returnUrl) { return new PaymentIntentParams() .setSourceParams(sourceParams) .setClientSecret(clientSecret) .setReturnUrl(returnUrl); }
@Test public void createCustomParams_toParamMap_createsExpectedMap() { PaymentIntentParams paymentIntentParams = PaymentIntentParams.createCustomParams(); paymentIntentParams .setReturnUrl(TEST_RETURN_URL) .setClientSecret(TEST_CLIENT_SECRET) .setSourceId(TEST_SOURCE_ID); Map<String, Object> paramMap = paymentIntentParams.toParamMap(); Assert.assertEquals(paramMap.get(PaymentIntentParams.API_PARAM_SOURCE_ID), TEST_SOURCE_ID); Assert.assertEquals( paramMap.get(PaymentIntentParams.API_PARAM_CLIENT_SECRET), TEST_CLIENT_SECRET); Assert.assertEquals( paramMap.get(PaymentIntentParams.API_PARAM_RETURN_URL), TEST_RETURN_URL); }
@Test public void createRetrievePaymentIntentWithSourceIdParams_hasExpectedFields() { PaymentIntentParams params = PaymentIntentParams.createRetrievePaymentIntentParams( TEST_CLIENT_SECRET); Assert.assertEquals(TEST_CLIENT_SECRET, params.getClientSecret()); Assert.assertNull(params.getReturnUrl()); Assert.assertNull(params.getExtraParams()); Assert.assertNull(params.getSourceId()); Assert.assertNull(params.getSourceParams()); }
@Test public void createConfirmPaymentIntentWithSourceDataParams_withAllFields_hasExpectedFields() { SourceParams sourceParams = SourceParams.createCardParams(FULL_FIELDS_VISA_CARD); PaymentIntentParams params = PaymentIntentParams.createConfirmPaymentIntentWithSourceDataParams( sourceParams, TEST_CLIENT_SECRET, TEST_RETURN_URL); Assert.assertEquals(TEST_CLIENT_SECRET, params.getClientSecret()); Assert.assertEquals(TEST_RETURN_URL, params.getReturnUrl()); Assert.assertEquals(sourceParams, params.getSourceParams()); }
APIConnectionException, APIException { final Map<String, Object> paramMap = paymentIntentParams.toParamMap(); StripeNetworkUtils.addUidParamsToPaymentIntent(uidProvider, context, paramMap); final RequestOptions options = RequestOptions.builder( final SourceParams sourceParams = paymentIntentParams.getSourceParams(); final String sourceType = sourceParams != null ? sourceParams.getType() : null; final Map<String, Object> loggingParams = LoggingUtils logApiCall(loggingParams, loggingOptions, loggingResponseListener); final String paymentIntentId = PaymentIntent.parseIdFromClientSecret( paymentIntentParams.getClientSecret()); final StripeResponse response = requestData( POST, confirmPaymentIntentUrl(paymentIntentId), paramMap, options);
@Test public void createConfirmPaymentIntentWithSourceIdParams_withAllFields_hasExpectedFields() { PaymentIntentParams params = PaymentIntentParams.createConfirmPaymentIntentWithSourceIdParams( TEST_SOURCE_ID, TEST_CLIENT_SECRET, TEST_RETURN_URL); Assert.assertEquals(TEST_CLIENT_SECRET, params.getClientSecret()); Assert.assertEquals(TEST_RETURN_URL, params.getReturnUrl()); Assert.assertEquals(TEST_SOURCE_ID, params.getSourceId()); }
@Test public void toParamMap_whenExtraParamsProvided_createsExpectedMap() { PaymentIntentParams paymentIntentParams = PaymentIntentParams.createRetrievePaymentIntentParams( TEST_CLIENT_SECRET); Map<String, Object> extraParams = new HashMap<>(); String extraParamKey1 = "extra_param_key_1"; String extraParamKey2 = "extra_param_key_2"; String extraParamValue1 = "extra_param_value_1"; String extraParamValue2 = "extra_param_value_2"; extraParams.put(extraParamKey1, extraParamValue1); extraParams.put(extraParamKey2, extraParamValue2); paymentIntentParams.setExtraParams(extraParams); Map<String, Object> paramMap = paymentIntentParams.toParamMap(); Assert.assertEquals( paramMap.get(PaymentIntentParams.API_PARAM_CLIENT_SECRET), TEST_CLIENT_SECRET); Assert.assertEquals( paramMap.get(extraParamKey1), extraParamValue1); Assert.assertEquals( paramMap.get(extraParamKey2), extraParamValue2); }
APIConnectionException, APIException { final Map<String, Object> paramMap = paymentIntentParams.toParamMap(); final RequestOptions options = RequestOptions.builder( publishableKey, logApiCall(loggingParams, loggingOptions, loggingResponseListener); final String paymentIntentId = PaymentIntent.parseIdFromClientSecret( paymentIntentParams.getClientSecret()); final StripeResponse response = requestData(GET, retrievePaymentIntentUrl(paymentIntentId), paramMap, options);
@Override public PaymentIntent call() throws Exception { PaymentIntentParams paymentIntentParams = PaymentIntentParams.createConfirmPaymentIntentWithSourceDataParams( sourceParams, clientSecret, RETURN_URL); return mStripe.confirmPaymentIntentSynchronous( paymentIntentParams, PaymentConfiguration.getInstance().getPublishableKey()); } });
@Override public PaymentIntent call() throws Exception { PaymentIntentParams paymentIntentParams = PaymentIntentParams.createRetrievePaymentIntentParams(clientSecret); return mStripe.retrievePaymentIntentSynchronous( paymentIntentParams, PaymentConfiguration.getInstance().getPublishableKey()); } });
/** * Create a custom {@link PaymentIntentParams}. Incorrect attributes may result in errors * when connecting to Stripe's API. * * @return an empty Params object. Call the setter methods on this class to specific values on * the params */ public static PaymentIntentParams createCustomParams() { return new PaymentIntentParams(); }
@Ignore public void disabled_confirmPaymentIntent_withSourceId_canSuccessfulConfirm() { String clientSecret = "temporarily put a private key here simulate the backend"; String publicKey = "put a public key that matches the private key here"; String sourceId = "id of the source created on the backend"; try { PaymentIntentParams paymentIntentParams = PaymentIntentParams.createConfirmPaymentIntentWithSourceIdParams( sourceId, clientSecret, null ); PaymentIntent paymentIntent = StripeApiHandler.confirmPaymentIntent( null, ApplicationProvider.getApplicationContext(), paymentIntentParams, publicKey, null, null); assertNotNull(paymentIntent); } catch (AuthenticationException authEx) { fail("Unexpected error: " + authEx.getLocalizedMessage()); } catch (StripeException stripeEx) { fail("Unexpected error when connecting to Stripe API: " + stripeEx.getLocalizedMessage()); } }
@Ignore public void disabled_confirmPaymentIntent_withSourceData_canSuccessfulConfirm() { String clientSecret = "temporarily put a private key here simulate the backend"; String publicKey = "put a public key that matches the private key here"; try { Card card = new Card("4242424242424242", 1, 2050, "123"); PaymentIntentParams paymentIntentParams = PaymentIntentParams.createConfirmPaymentIntentWithSourceDataParams( SourceParams.createCardParams(card), clientSecret, null ); PaymentIntent paymentIntent = StripeApiHandler.confirmPaymentIntent( null, ApplicationProvider.getApplicationContext(), paymentIntentParams, publicKey, null, null); assertNotNull(paymentIntent); } catch (AuthenticationException authEx) { fail("Unexpected error: " + authEx.getLocalizedMessage()); } catch (StripeException stripeEx) { fail("Unexpected error when connecting to Stripe API: " + stripeEx.getLocalizedMessage()); } }
@Ignore public void disabled_confirmRetrieve_withSourceId_canSuccessfulRetrieve() { String clientSecret = "temporarily put a private key here simulate the backend"; String publicKey = "put a public key that matches the private key here"; try { PaymentIntentParams paymentIntentParams = PaymentIntentParams.createRetrievePaymentIntentParams( clientSecret ); PaymentIntent paymentIntent = StripeApiHandler.retrievePaymentIntent( ApplicationProvider.getApplicationContext(), paymentIntentParams, publicKey, null, null); assertNotNull(paymentIntent); } catch (AuthenticationException authEx) { fail("Unexpected error: " + authEx.getLocalizedMessage()); } catch (StripeException stripeEx) { fail("Unexpected error when connecting to Stripe API: " + stripeEx.getLocalizedMessage()); } }