From 6fc6bc4c74b550e78cdb830d4be2ad4486859c62 Mon Sep 17 00:00:00 2001 From: Jason Emerick Date: Thu, 6 Jun 2019 16:46:06 -0400 Subject: [PATCH 01/10] Update total price handling for button and actually charging --- .../com/stripe/samplestore/PaymentActivity.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java b/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java index 61162fd8086..709281ebfca 100644 --- a/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java +++ b/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java @@ -99,6 +99,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { addCartItems(); + setupPaymentSession(); + mConfirmPaymentButton = findViewById(R.id.btn_purchase); updateConfirmPaymentButton(); mEnterShippingInfo = findViewById(R.id.shipping_info); @@ -112,8 +114,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { new AttemptPurchaseCustomerRetrievalListener( PaymentActivity.this)))); - setupPaymentSession(); - mConfirmPaymentButton.setEnabled(mPaymentSession.getPaymentSessionData() .isPaymentReadyToCharge()); @@ -184,7 +184,7 @@ public void onError(@NonNull Exception e) { } private void updateConfirmPaymentButton() { - long price = mStoreCart.getTotalPrice(); + final long price = mPaymentSession.getPaymentSessionData().getCartTotal(); mConfirmPaymentButton.setText(String.format(Locale.ENGLISH, "Pay %s", StoreUtils.getPriceString(price, null))); @@ -218,7 +218,7 @@ private void addLineItems(@NonNull String currencySymbol, @NonNull StoreLineItem private void setupTotalPriceView(@NonNull View view, @NonNull String currencySymbol) { final TextView[] itemViews = getItemViews(view); - final long totalPrice = mStoreCart.getTotalPrice() + mShippingCosts; + final long totalPrice = mPaymentSession.getPaymentSessionData().getCartTotal(); itemViews[0].setText(getString(R.string.checkout_total_cost_label)); final String price = PayWithGoogleUtils.getPriceString(totalPrice, mStoreCart.getCurrency()); @@ -348,7 +348,9 @@ private void finishPayment() { private void setupPaymentSession() { mPaymentSession = new PaymentSession(this); mPaymentSession.init(new PaymentSessionListenerImpl(this), - new PaymentSessionConfig.Builder().build()); + new PaymentSessionConfig.Builder() + .setPrepopulatedShippingInfo(getExampleShippingInfo()).build()); + mPaymentSession.setCartTotal(mStoreCart.getTotalPrice()); } private void startLoading() { @@ -393,6 +395,7 @@ private void onPaymentSessionDataChanged(@NonNull PaymentSessionData data) { if (data.getShippingMethod() != null) { mEnterShippingInfo.setText(data.getShippingMethod().getLabel()); mShippingCosts = data.getShippingMethod().getAmount(); + mPaymentSession.setCartTotal(mStoreCart.getTotalPrice() + mShippingCosts); addCartItems(); updateConfirmPaymentButton(); } From fc5a175afdc7dd65421cd865f86113ce473f33c2 Mon Sep 17 00:00:00 2001 From: Jason Emerick Date: Thu, 6 Jun 2019 16:46:32 -0400 Subject: [PATCH 02/10] update createCapturePaymentParms to access the payment session data --- .../com/stripe/samplestore/PaymentActivity.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java b/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java index 709281ebfca..1a631ebcfbe 100644 --- a/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java +++ b/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java @@ -258,16 +258,14 @@ private TextView[] getItemViews(@NonNull View view) { } @NonNull - private Map createCapturePaymentParams( - long price, - @NonNull String paymentMethodId, - @NonNull String customerId, - @Nullable ShippingInformation shippingInformation) { + private Map createCapturePaymentParams(@NonNull PaymentSessionData data, + @NonNull String customerId) { final AbstractMap params = new HashMap<>(); - params.put("amount", Long.toString(price)); - params.put("payment_method", paymentMethodId); + params.put("amount", Long.toString(data.getCartTotal())); + params.put("payment_method", Objects.requireNonNull(data.getPaymentMethod()).id); params.put("customer_id", customerId); - params.put("shipping", shippingInformation != null ? shippingInformation.toMap() : null); + params.put("shipping", data.getShippingInformation() != null ? + data.getShippingInformation().toMap() : null); params.put("return_url", "stripe://payment-auth-return"); return params; } From bebaa066ca5439de676a0ed07329860f2f5509f7 Mon Sep 17 00:00:00 2001 From: Jason Emerick Date: Thu, 6 Jun 2019 16:51:39 -0400 Subject: [PATCH 03/10] provide example shipping info --- .../com/stripe/samplestore/PaymentActivity.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java b/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java index 1a631ebcfbe..d00dab9905e 100644 --- a/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java +++ b/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java @@ -29,6 +29,7 @@ import com.stripe.android.PaymentSessionData; import com.stripe.android.Stripe; import com.stripe.android.StripeError; +import com.stripe.android.model.Address; import com.stripe.android.model.Customer; import com.stripe.android.model.PaymentIntent; import com.stripe.android.model.PaymentMethod; @@ -149,6 +150,19 @@ private boolean isShippingInfoValid(@NonNull ShippingInformation shippingInfo) { Locale.US.getCountry().equals(shippingInfo.getAddress().getCountry()); } + @NonNull + private ShippingInformation getExampleShippingInfo() { + final Address address = new Address.Builder() + .setCity("San Francisco") + .setCountry("US") + .setLine1("123 Market St") + .setLine2("#345") + .setPostalCode("94107") + .setState("CA") + .build(); + return new ShippingInformation(address, "Fake Name", "(555) 555-5555"); + } + /* * Cleaning up all Rx subscriptions in onDestroy. */ From 580a829df5054eb3e77912a62418df48d2379ee3 Mon Sep 17 00:00:00 2001 From: Jason Emerick Date: Fri, 7 Jun 2019 12:29:19 -0400 Subject: [PATCH 04/10] update payment activity capture payment to use createCapturePaymentParams --- .../com/stripe/samplestore/PaymentActivity.java | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java b/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java index d00dab9905e..41da73a9c66 100644 --- a/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java +++ b/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java @@ -285,22 +285,13 @@ private Map createCapturePaymentParams(@NonNull PaymentSessionDa } private void capturePayment(@NonNull String customerId) { - final long price = mStoreCart.getTotalPrice() + mShippingCosts; - - final PaymentMethod paymentMethod = - mPaymentSession.getPaymentSessionData().getPaymentMethod(); - - if (paymentMethod == null) { + if (mPaymentSession.getPaymentSessionData().getPaymentMethod() == null) { displayError("No payment method selected"); return; } - final ShippingInformation shippingInformation = mPaymentSession.getPaymentSessionData() - .getShippingInformation(); - final Observable stripeResponse = mService.capturePayment( - createCapturePaymentParams(price, Objects.requireNonNull(paymentMethod.id), - customerId, shippingInformation)); + createCapturePaymentParams(mPaymentSession.getPaymentSessionData(), customerId)); mCompositeDisposable.add(stripeResponse .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) From 06e8d030c9ee8c10a4e9ac370469bc5cad6c1316 Mon Sep 17 00:00:00 2001 From: Jason Emerick Date: Fri, 7 Jun 2019 12:30:39 -0400 Subject: [PATCH 05/10] setupPaymentSession before adding cart items --- .../src/main/java/com/stripe/samplestore/PaymentActivity.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java b/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java index 41da73a9c66..cd6c87c645b 100644 --- a/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java +++ b/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java @@ -98,10 +98,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { mProgressBar = findViewById(R.id.progress_bar); mCartItemLayout = findViewById(R.id.cart_list_items); - addCartItems(); - setupPaymentSession(); + addCartItems(); + mConfirmPaymentButton = findViewById(R.id.btn_purchase); updateConfirmPaymentButton(); mEnterShippingInfo = findViewById(R.id.shipping_info); From 61a4a6d0a52f48dc700e259aa90439a9fbaca02d Mon Sep 17 00:00:00 2001 From: Jason Emerick Date: Fri, 7 Jun 2019 12:40:24 -0400 Subject: [PATCH 06/10] Display error on error --- .../src/main/java/com/stripe/samplestore/PaymentActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java b/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java index cd6c87c645b..6ea39fd7f0a 100644 --- a/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java +++ b/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java @@ -188,7 +188,7 @@ public void onSuccess(@NonNull PaymentAuthResult result) { @Override public void onError(@NonNull Exception e) { - finishPayment(); + displayError(e.getMessage()); } }); From 7f34eff7b4ff60a3606530c6ef3a0a12c8b8f0aa Mon Sep 17 00:00:00 2001 From: Jason Emerick Date: Fri, 7 Jun 2019 13:04:35 -0400 Subject: [PATCH 07/10] Remove payment completion provider, payment result listener --- .../stripe/samplestore/PaymentActivity.java | 2 +- .../android/PaymentCompletionProvider.java | 19 ----------- .../stripe/android/PaymentResultListener.java | 32 ------------------- .../com/stripe/android/PaymentSession.java | 19 ++--------- .../stripe/android/PaymentSessionData.java | 24 ++------------ .../stripe/android/PaymentSessionUtils.java | 30 ----------------- .../stripe/android/PaymentSessionTest.java | 16 ++-------- 7 files changed, 8 insertions(+), 134 deletions(-) delete mode 100644 stripe/src/main/java/com/stripe/android/PaymentCompletionProvider.java delete mode 100644 stripe/src/main/java/com/stripe/android/PaymentResultListener.java delete mode 100644 stripe/src/main/java/com/stripe/android/PaymentSessionUtils.java diff --git a/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java b/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java index 6ea39fd7f0a..fd9ba7fd8b8 100644 --- a/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java +++ b/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java @@ -318,7 +318,7 @@ private void processPaymentIntent(@NonNull PaymentIntent paymentIntent) { confirmPaymentIntent(Objects.requireNonNull(paymentIntent.getId())); return; } - + mPaymentSession.onCompleted(); finishPayment(); } diff --git a/stripe/src/main/java/com/stripe/android/PaymentCompletionProvider.java b/stripe/src/main/java/com/stripe/android/PaymentCompletionProvider.java deleted file mode 100644 index d2d9628f7f3..00000000000 --- a/stripe/src/main/java/com/stripe/android/PaymentCompletionProvider.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.stripe.android; - -import android.support.annotation.NonNull; - -/** - * Represents a class that can call to a server and process a charge based on input payment data. - */ -public interface PaymentCompletionProvider { - - /** - * Called to complete a charge action. Note that this method should handle its own threading, - * as it will be called on the UI thread, and it should notify the listener on the UI thread. - * - * @param data the {@link PaymentSessionData} to be used to create a charge - * @param listener a {@link PaymentResultListener} to notify of the result - */ - void completePayment(@NonNull PaymentSessionData data, - @NonNull PaymentResultListener listener); -} diff --git a/stripe/src/main/java/com/stripe/android/PaymentResultListener.java b/stripe/src/main/java/com/stripe/android/PaymentResultListener.java deleted file mode 100644 index b228a314cdb..00000000000 --- a/stripe/src/main/java/com/stripe/android/PaymentResultListener.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.stripe.android; - -import android.support.annotation.NonNull; -import android.support.annotation.StringDef; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -/** - * Represents a listener for the result of payment calls. - */ -public interface PaymentResultListener { - - @Retention(RetentionPolicy.SOURCE) - @StringDef({ - SUCCESS, - USER_CANCELLED, - ERROR, - INCOMPLETE - }) - @interface PaymentResult { } - String SUCCESS = "success"; - String USER_CANCELLED = "user_cancelled"; - String ERROR = "error"; - String INCOMPLETE = "incomplete"; - - /** - * Called to notify the listener of the result of the payment. - * @param paymentResult success, user_cancelled, or error - */ - void onPaymentResult(@NonNull @PaymentResult String paymentResult); -} diff --git a/stripe/src/main/java/com/stripe/android/PaymentSession.java b/stripe/src/main/java/com/stripe/android/PaymentSession.java index 686e57d7c37..a7ef2b9bbf2 100644 --- a/stripe/src/main/java/com/stripe/android/PaymentSession.java +++ b/stripe/src/main/java/com/stripe/android/PaymentSession.java @@ -65,23 +65,10 @@ public PaymentSession(@NonNull Activity hostActivity) { } /** - * Complete a payment using the given provider. - * @param provider a {@link PaymentCompletionProvider} that connects to a server and completes - * a charge on a background thread. + * Notify this payment session that it is complete */ - public void completePayment(@NonNull PaymentCompletionProvider provider) { - provider.completePayment(mPaymentSessionData, - new PaymentResultListener() { - @Override - public void onPaymentResult(@NonNull @PaymentResult String paymentResult) { - mPaymentSessionData.setPaymentResult(paymentResult); - mCustomerSession.resetUsageTokens(); - if (mPaymentSessionListener != null) { - mPaymentSessionListener - .onPaymentSessionDataChanged(mPaymentSessionData); - } - } - }); + public void onCompleted() { + mCustomerSession.resetUsageTokens(); } /** diff --git a/stripe/src/main/java/com/stripe/android/PaymentSessionData.java b/stripe/src/main/java/com/stripe/android/PaymentSessionData.java index 539141c7a5e..4ddec29c4cf 100644 --- a/stripe/src/main/java/com/stripe/android/PaymentSessionData.java +++ b/stripe/src/main/java/com/stripe/android/PaymentSessionData.java @@ -18,8 +18,6 @@ public class PaymentSessionData implements Parcelable { private long mCartTotal = 0L; private boolean mIsPaymentReadyToCharge; private long mShippingTotal = 0L; - @NonNull @PaymentResultListener.PaymentResult private String mPaymentResult = - PaymentResultListener.INCOMPLETE; @Nullable private ShippingInformation mShippingInformation; @Nullable private ShippingMethod mShippingMethod; @Nullable private PaymentMethod mPaymentMethod; @@ -43,17 +41,6 @@ public long getCartTotal() { return mCartTotal; } - /** - * Get the payment result for this PaymentSession. - * - * @return the current payment result for this session, or INCOMPLETE if not yet finished - */ - @NonNull - @PaymentResultListener.PaymentResult - public String getPaymentResult() { - return mPaymentResult; - } - /** * Get the whether the all the payment data is ready for making a charge. This can be used to * set a buy button to enabled for prompt a user to fill in more information. @@ -127,10 +114,6 @@ void setCartTotal(long cartTotal) { mCartTotal = cartTotal; } - void setPaymentResult(@NonNull @PaymentResultListener.PaymentResult String result) { - mPaymentResult = result; - } - void setPaymentMethod(@Nullable PaymentMethod paymentMethod) { mPaymentMethod = paymentMethod; } @@ -169,14 +152,13 @@ private boolean typedEquals(@NonNull PaymentSessionData data) { && ObjectUtils.equals(mShippingTotal, data.mShippingTotal) && ObjectUtils.equals(mShippingInformation, data.mShippingInformation) && ObjectUtils.equals(mShippingMethod, data.mShippingMethod) - && ObjectUtils.equals(mPaymentMethod, data.mPaymentMethod) - && ObjectUtils.equals(mPaymentResult, data.mPaymentResult); + && ObjectUtils.equals(mPaymentMethod, data.mPaymentMethod); } @Override public int hashCode() { return ObjectUtils.hash(mCartTotal, mIsPaymentReadyToCharge, mPaymentMethod, - mShippingTotal, mPaymentResult, mShippingInformation, mShippingMethod); + mShippingTotal, mShippingInformation, mShippingMethod); } /************** Parcelable *********************/ @@ -189,7 +171,6 @@ public int describeContents() { public void writeToParcel(Parcel parcel, int i) { parcel.writeLong(mCartTotal); parcel.writeInt(mIsPaymentReadyToCharge ? 1 : 0); - parcel.writeString(mPaymentResult); parcel.writeString(mPaymentMethod != null ? mPaymentMethod.toJson().toString() : null); parcel.writeParcelable(mShippingInformation, i); parcel.writeParcelable(mShippingMethod, i); @@ -211,7 +192,6 @@ public PaymentSessionData[] newArray(int size) { private PaymentSessionData(@NonNull Parcel in) { mCartTotal = in.readLong(); mIsPaymentReadyToCharge = in.readInt() == 1; - mPaymentResult = PaymentSessionUtils.paymentResultFromString(in.readString()); mPaymentMethod = PaymentMethod.fromString(in.readString()); mShippingInformation = in.readParcelable(ShippingInformation.class.getClassLoader()); mShippingMethod = in.readParcelable(ShippingMethod.class.getClassLoader()); diff --git a/stripe/src/main/java/com/stripe/android/PaymentSessionUtils.java b/stripe/src/main/java/com/stripe/android/PaymentSessionUtils.java deleted file mode 100644 index a0ca899b700..00000000000 --- a/stripe/src/main/java/com/stripe/android/PaymentSessionUtils.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.stripe.android; - - -import android.support.annotation.NonNull; - -import static com.stripe.android.PaymentResultListener.ERROR; -import static com.stripe.android.PaymentResultListener.INCOMPLETE; -import static com.stripe.android.PaymentResultListener.SUCCESS; -import static com.stripe.android.PaymentResultListener.USER_CANCELLED; - -class PaymentSessionUtils { - - @NonNull - @PaymentResultListener.PaymentResult - public static String paymentResultFromString(String paymentResultRaw) { - switch (paymentResultRaw) { - case SUCCESS: - return SUCCESS; - case USER_CANCELLED: - return USER_CANCELLED; - case ERROR: - return ERROR; - case INCOMPLETE: - return INCOMPLETE; - default: - return ERROR; - } - } - -} diff --git a/stripe/src/test/java/com/stripe/android/PaymentSessionTest.java b/stripe/src/test/java/com/stripe/android/PaymentSessionTest.java index e96bfe488fb..3cf55ecf678 100644 --- a/stripe/src/test/java/com/stripe/android/PaymentSessionTest.java +++ b/stripe/src/test/java/com/stripe/android/PaymentSessionTest.java @@ -277,20 +277,8 @@ public void completePayment_withLoggedActions_clearsLoggingTokensAndSetsResult() assertEquals(2, loggingTokens.size()); reset(mPaymentSessionListener); - paymentSession.completePayment(new PaymentCompletionProvider() { - @Override - public void completePayment(@NonNull PaymentSessionData data, - @NonNull PaymentResultListener listener) { - listener.onPaymentResult(PaymentResultListener.SUCCESS); - } - }); - - ArgumentCaptor dataArgumentCaptor = - ArgumentCaptor.forClass(PaymentSessionData.class); - verify(mPaymentSessionListener).onPaymentSessionDataChanged(dataArgumentCaptor.capture()); - PaymentSessionData capturedData = dataArgumentCaptor.getValue(); - assertNotNull(capturedData); - assertEquals(PaymentResultListener.SUCCESS, capturedData.getPaymentResult()); + + paymentSession.onCompleted(); assertTrue(customerSession.getProductUsageTokens().isEmpty()); } From 4517aa9d3355f83dc79d82e3083e8fe843c56a76 Mon Sep 17 00:00:00 2001 From: Jason Emerick Date: Tue, 11 Jun 2019 15:15:09 -0400 Subject: [PATCH 08/10] move payment session on complete --- build.gradle | 1 + .../java/com/stripe/example/activity/LauncherActivity.java | 2 +- .../main/java/com/stripe/example/module/RetrofitFactory.java | 2 +- .../src/main/java/com/stripe/samplestore/PaymentActivity.java | 3 ++- .../src/main/java/com/stripe/samplestore/RetrofitFactory.java | 2 +- .../src/main/java/com/stripe/samplestore/StoreActivity.java | 2 +- 6 files changed, 7 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index fbf51b3a893..440c8067c3b 100644 --- a/build.gradle +++ b/build.gradle @@ -18,6 +18,7 @@ allprojects { repositories { google() jcenter() + mavenLocal() } task checkstyle(type: Checkstyle) { diff --git a/example/src/main/java/com/stripe/example/activity/LauncherActivity.java b/example/src/main/java/com/stripe/example/activity/LauncherActivity.java index b7e76a0a3a7..804db47f4ea 100644 --- a/example/src/main/java/com/stripe/example/activity/LauncherActivity.java +++ b/example/src/main/java/com/stripe/example/activity/LauncherActivity.java @@ -26,7 +26,7 @@ public class LauncherActivity extends AppCompatActivity { * You can get your key here: https://dashboard.stripe.com/account/apikeys */ private static final String PUBLISHABLE_KEY = - "put your key here"; + "pk_test_pWjWlOKXD13QQ1o31awb0IM000u9Xq3Hxd"; @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/example/src/main/java/com/stripe/example/module/RetrofitFactory.java b/example/src/main/java/com/stripe/example/module/RetrofitFactory.java index c599976d368..fe69c96958f 100644 --- a/example/src/main/java/com/stripe/example/module/RetrofitFactory.java +++ b/example/src/main/java/com/stripe/example/module/RetrofitFactory.java @@ -19,7 +19,7 @@ public class RetrofitFactory { // Put your Base URL here. Unless you customized it, the URL will be something like // https://hidden-beach-12345.herokuapp.com/ - private static final String BASE_URL = "put your url here"; + private static final String BASE_URL = "https://jemerick-stripe-3ds2.herokuapp.com/"; @Nullable private static Retrofit mInstance = null; @NonNull diff --git a/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java b/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java index f0f6bfbbb33..d1f08f5003d 100644 --- a/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java +++ b/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java @@ -318,7 +318,7 @@ private void processPaymentIntent(@NonNull PaymentIntent paymentIntent) { confirmPaymentIntent(Objects.requireNonNull(paymentIntent.getId())); return; } - mPaymentSession.onCompleted(); + finishPayment(); } @@ -342,6 +342,7 @@ private void onPaymentIntentResponse(@NonNull ResponseBody responseBody) throws } private void finishPayment() { + mPaymentSession.onCompleted(); final Intent data = StoreActivity.createPurchaseCompleteIntent( mStoreCart.getTotalPrice() + mShippingCosts); setResult(RESULT_OK, data); diff --git a/samplestore/src/main/java/com/stripe/samplestore/RetrofitFactory.java b/samplestore/src/main/java/com/stripe/samplestore/RetrofitFactory.java index 59a0d37c37e..053ac4942f9 100644 --- a/samplestore/src/main/java/com/stripe/samplestore/RetrofitFactory.java +++ b/samplestore/src/main/java/com/stripe/samplestore/RetrofitFactory.java @@ -19,7 +19,7 @@ public class RetrofitFactory { // Put your Base URL here. Unless you customized it, the URL will be something like // https://hidden-beach-12345.herokuapp.com/ - private static final String BASE_URL = "put your base url here"; + private static final String BASE_URL = "https://jemerick-stripe-3ds2.herokuapp.com/"; @Nullable private static Retrofit mInstance = null; @NonNull diff --git a/samplestore/src/main/java/com/stripe/samplestore/StoreActivity.java b/samplestore/src/main/java/com/stripe/samplestore/StoreActivity.java index c203d6aa23a..977233626dc 100644 --- a/samplestore/src/main/java/com/stripe/samplestore/StoreActivity.java +++ b/samplestore/src/main/java/com/stripe/samplestore/StoreActivity.java @@ -40,7 +40,7 @@ public class StoreActivity * You can get your key here: https://dashboard.stripe.com/account/apikeys */ private static final String PUBLISHABLE_KEY = - "put your publishable key here"; + "pk_test_pWjWlOKXD13QQ1o31awb0IM000u9Xq3Hxd"; static final int PURCHASE_REQUEST = 37; From a0b431e375584b43582246b3962033bebf24a61a Mon Sep 17 00:00:00 2001 From: Jason Emerick Date: Tue, 11 Jun 2019 16:04:45 -0400 Subject: [PATCH 09/10] Revert "move payment session on complete" This reverts commit 4517aa9d3355f83dc79d82e3083e8fe843c56a76. --- build.gradle | 1 - .../java/com/stripe/example/activity/LauncherActivity.java | 2 +- .../main/java/com/stripe/example/module/RetrofitFactory.java | 2 +- .../src/main/java/com/stripe/samplestore/PaymentActivity.java | 3 +-- .../src/main/java/com/stripe/samplestore/RetrofitFactory.java | 2 +- .../src/main/java/com/stripe/samplestore/StoreActivity.java | 2 +- 6 files changed, 5 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index 440c8067c3b..fbf51b3a893 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,6 @@ allprojects { repositories { google() jcenter() - mavenLocal() } task checkstyle(type: Checkstyle) { diff --git a/example/src/main/java/com/stripe/example/activity/LauncherActivity.java b/example/src/main/java/com/stripe/example/activity/LauncherActivity.java index 804db47f4ea..b7e76a0a3a7 100644 --- a/example/src/main/java/com/stripe/example/activity/LauncherActivity.java +++ b/example/src/main/java/com/stripe/example/activity/LauncherActivity.java @@ -26,7 +26,7 @@ public class LauncherActivity extends AppCompatActivity { * You can get your key here: https://dashboard.stripe.com/account/apikeys */ private static final String PUBLISHABLE_KEY = - "pk_test_pWjWlOKXD13QQ1o31awb0IM000u9Xq3Hxd"; + "put your key here"; @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/example/src/main/java/com/stripe/example/module/RetrofitFactory.java b/example/src/main/java/com/stripe/example/module/RetrofitFactory.java index fe69c96958f..c599976d368 100644 --- a/example/src/main/java/com/stripe/example/module/RetrofitFactory.java +++ b/example/src/main/java/com/stripe/example/module/RetrofitFactory.java @@ -19,7 +19,7 @@ public class RetrofitFactory { // Put your Base URL here. Unless you customized it, the URL will be something like // https://hidden-beach-12345.herokuapp.com/ - private static final String BASE_URL = "https://jemerick-stripe-3ds2.herokuapp.com/"; + private static final String BASE_URL = "put your url here"; @Nullable private static Retrofit mInstance = null; @NonNull diff --git a/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java b/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java index d1f08f5003d..f0f6bfbbb33 100644 --- a/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java +++ b/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java @@ -318,7 +318,7 @@ private void processPaymentIntent(@NonNull PaymentIntent paymentIntent) { confirmPaymentIntent(Objects.requireNonNull(paymentIntent.getId())); return; } - + mPaymentSession.onCompleted(); finishPayment(); } @@ -342,7 +342,6 @@ private void onPaymentIntentResponse(@NonNull ResponseBody responseBody) throws } private void finishPayment() { - mPaymentSession.onCompleted(); final Intent data = StoreActivity.createPurchaseCompleteIntent( mStoreCart.getTotalPrice() + mShippingCosts); setResult(RESULT_OK, data); diff --git a/samplestore/src/main/java/com/stripe/samplestore/RetrofitFactory.java b/samplestore/src/main/java/com/stripe/samplestore/RetrofitFactory.java index 053ac4942f9..59a0d37c37e 100644 --- a/samplestore/src/main/java/com/stripe/samplestore/RetrofitFactory.java +++ b/samplestore/src/main/java/com/stripe/samplestore/RetrofitFactory.java @@ -19,7 +19,7 @@ public class RetrofitFactory { // Put your Base URL here. Unless you customized it, the URL will be something like // https://hidden-beach-12345.herokuapp.com/ - private static final String BASE_URL = "https://jemerick-stripe-3ds2.herokuapp.com/"; + private static final String BASE_URL = "put your base url here"; @Nullable private static Retrofit mInstance = null; @NonNull diff --git a/samplestore/src/main/java/com/stripe/samplestore/StoreActivity.java b/samplestore/src/main/java/com/stripe/samplestore/StoreActivity.java index 977233626dc..c203d6aa23a 100644 --- a/samplestore/src/main/java/com/stripe/samplestore/StoreActivity.java +++ b/samplestore/src/main/java/com/stripe/samplestore/StoreActivity.java @@ -40,7 +40,7 @@ public class StoreActivity * You can get your key here: https://dashboard.stripe.com/account/apikeys */ private static final String PUBLISHABLE_KEY = - "pk_test_pWjWlOKXD13QQ1o31awb0IM000u9Xq3Hxd"; + "put your publishable key here"; static final int PURCHASE_REQUEST = 37; From 5c933d8e31b96a8b56f662765210812789fe60bb Mon Sep 17 00:00:00 2001 From: Jason Emerick Date: Tue, 11 Jun 2019 16:10:17 -0400 Subject: [PATCH 10/10] Finish on success only, move to finish --- .../java/com/stripe/samplestore/PaymentActivity.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java b/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java index f0f6bfbbb33..38e2fe2931d 100644 --- a/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java +++ b/samplestore/src/main/java/com/stripe/samplestore/PaymentActivity.java @@ -313,13 +313,14 @@ private void displayError(@NonNull String errorMessage) { private void processPaymentIntent(@NonNull PaymentIntent paymentIntent) { if (paymentIntent.requiresAction()) { mStripe.authenticatePayment(this, paymentIntent); - return; } else if (paymentIntent.requiresConfirmation()) { confirmPaymentIntent(Objects.requireNonNull(paymentIntent.getId())); - return; + } else if (paymentIntent.getStatus() == PaymentIntent.Status.Succeeded) { + finishPayment(); + } else { + displayError( + "Unhandled Payment Intent Status: " + paymentIntent.getStatus().toString()); } - mPaymentSession.onCompleted(); - finishPayment(); } private void confirmPaymentIntent(@NonNull String paymentIntentId) { @@ -342,6 +343,7 @@ private void onPaymentIntentResponse(@NonNull ResponseBody responseBody) throws } private void finishPayment() { + mPaymentSession.onCompleted(); final Intent data = StoreActivity.createPurchaseCompleteIntent( mStoreCart.getTotalPrice() + mShippingCosts); setResult(RESULT_OK, data);