diff --git a/stripe_android/android/build.gradle b/stripe_android/android/build.gradle new file mode 100644 index 0000000..92c78fa --- /dev/null +++ b/stripe_android/android/build.gradle @@ -0,0 +1,4 @@ +dependencies { + implementation 'com.google.code.gson:gson:2.10.1' + implementation "com.stripe:stripe-java:22.21.0" +} diff --git a/stripe_android/android/dist/com.ravindra.stripe-android-3.0.zip b/stripe_android/android/dist/com.ravindra.stripe-android-3.0.zip deleted file mode 100644 index 14fbbaf..0000000 Binary files a/stripe_android/android/dist/com.ravindra.stripe-android-3.0.zip and /dev/null differ diff --git a/stripe_android/android/dist/com.ravindra.stripe-android-4.0.0.zip b/stripe_android/android/dist/com.ravindra.stripe-android-4.0.0.zip new file mode 100644 index 0000000..003ea2a Binary files /dev/null and b/stripe_android/android/dist/com.ravindra.stripe-android-4.0.0.zip differ diff --git a/stripe_android/android/dist/stripe_android.jar b/stripe_android/android/dist/stripe_android.jar deleted file mode 100644 index dfd54d8..0000000 Binary files a/stripe_android/android/dist/stripe_android.jar and /dev/null differ diff --git a/stripe_android/android/lib/README b/stripe_android/android/lib/README deleted file mode 100644 index a54313f..0000000 --- a/stripe_android/android/lib/README +++ /dev/null @@ -1,2 +0,0 @@ -You can place any .jar dependencies in this directory and they will be included -when your module is being compiled. \ No newline at end of file diff --git a/stripe_android/android/lib/gson-2.8.2.jar b/stripe_android/android/lib/gson-2.8.2.jar deleted file mode 100644 index d0d030c..0000000 Binary files a/stripe_android/android/lib/gson-2.8.2.jar and /dev/null differ diff --git a/stripe_android/android/lib/stripe-java-1.15.1.jar b/stripe_android/android/lib/stripe-java-1.15.1.jar deleted file mode 100644 index b8abce9..0000000 Binary files a/stripe_android/android/lib/stripe-java-1.15.1.jar and /dev/null differ diff --git a/stripe_android/android/libs/armeabi-v7a/libcom.ravindra.stripe.so b/stripe_android/android/libs/armeabi-v7a/libcom.ravindra.stripe.so deleted file mode 100644 index b895d0f..0000000 Binary files a/stripe_android/android/libs/armeabi-v7a/libcom.ravindra.stripe.so and /dev/null differ diff --git a/stripe_android/android/libs/x86/libcom.ravindra.stripe.so b/stripe_android/android/libs/x86/libcom.ravindra.stripe.so deleted file mode 100644 index 4bac3b8..0000000 Binary files a/stripe_android/android/libs/x86/libcom.ravindra.stripe.so and /dev/null differ diff --git a/stripe_android/android/manifest b/stripe_android/android/manifest index 90eac7e..f90985d 100644 --- a/stripe_android/android/manifest +++ b/stripe_android/android/manifest @@ -2,9 +2,9 @@ # this is your module manifest and used by Titanium # during compilation, packaging, distribution, etc. # -version: 3.0 +version: 4.0.0 apiversion: 4 -architectures: arm64-v8a armeabi-v7a x86 +architectures: arm64-v8a armeabi-v7a x86 x86_64 description: Stripe payment library for Android author: Ravindra Chherke license: To Ravindra chherke @@ -15,4 +15,4 @@ name: stripe_android moduleid: com.ravindra.stripe guid: 89b4eaf4-d57f-4956-b6a3-deb3a635ac2c platform: android -minsdk: 7.0.0.GA +minsdk: 9.0.0 diff --git a/stripe_android/android/src/com/ravindra/stripe/StripeAndroidModule.java b/stripe_android/android/src/com/ravindra/stripe/StripeAndroidModule.java index 569521a..858cc41 100644 --- a/stripe_android/android/src/com/ravindra/stripe/StripeAndroidModule.java +++ b/stripe_android/android/src/com/ravindra/stripe/StripeAndroidModule.java @@ -47,31 +47,10 @@ public StripeAndroidModule() { @Kroll.onAppCreate public static void onAppCreate(TiApplication app) { - Log.d(LCAT, "inside onAppCreate"); - // put module init code that needs to run when the application is - // created } - // Methods - @Kroll.method - public String example() { - Log.d(LCAT, "example called"); - return "hello world"; - } - - // Properties - @Kroll.getProperty - public String getExampleProp() { - Log.d(LCAT, "get example property"); - return "hello world"; - } - @Kroll.setProperty - public void setExampleProp(String value) { - Log.d(LCAT, "set example property: " + value); - } - @SuppressWarnings({ "unchecked", "rawtypes" }) @Kroll.method public boolean setCard(HashMap propsIn) { KrollDict props = new KrollDict(propsIn); @@ -107,22 +86,12 @@ public boolean setCard(HashMap propsIn) { cvc = props.getString("cvc"); } - card = new Card(cardNumber, month, expiryYear, cvc); + card = new Card(cardNumber, (long) month, (long) expiryYear, cvc); return true; } - - /*@SuppressWarnings({ "unchecked", "rawtypes" }) - @Kroll.method - public String validateCard() { - - }*/ - - - - @SuppressWarnings({ "unchecked", "rawtypes" }) @Kroll.method public void requestForToken(HashMap args) { diff --git a/stripe_android/android/src/com/stripe/android/Stripe.java b/stripe_android/android/src/com/stripe/android/Stripe.java index 453da00..88268d7 100755 --- a/stripe_android/android/src/com/stripe/android/Stripe.java +++ b/stripe_android/android/src/com/stripe/android/Stripe.java @@ -1,29 +1,27 @@ package com.stripe.android; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.concurrent.Executor; - import com.stripe.android.compat.AsyncTask; import com.stripe.android.model.Card; import com.stripe.android.model.Token; import com.stripe.android.util.TextUtils; import com.stripe.exception.AuthenticationException; -public class Stripe { - private String defaultPublishableKey; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.concurrent.Executor; +public class Stripe { public TokenCreator tokenCreator = new TokenCreator() { @Override public void create(final Card card, final String publishableKey, final Executor executor, - final TokenCallback callback) { + final TokenCallback callback) { AsyncTask task = new AsyncTask() { protected ResponseWrapper doInBackground(Void... params) { try { com.stripe.model.Token stripeToken = com.stripe.model.Token.create( - hashMapFromCard(card), publishableKey); + hashMapFromCard(card)); com.stripe.model.Card stripeCard = stripeToken.getCard(); Card card = androidCardFromStripeCard(stripeCard); Token token = androidTokenFromStripeToken(card, stripeToken); @@ -35,22 +33,21 @@ protected ResponseWrapper doInBackground(Void... params) { protected void onPostExecute(ResponseWrapper result) { tokenTaskPostExecution(result, callback); - } + } }; executeTokenTask(executor, task); } }; - public TokenRequester tokenRequester = new TokenRequester() { - @Override - public void request(final String tokenId, final String publishableKey, - final Executor executor, final TokenCallback callback) { + @Override + public void request(final String tokenId, final String publishableKey, + final Executor executor, final TokenCallback callback) { AsyncTask task = new AsyncTask() { protected ResponseWrapper doInBackground(Void... params) { try { com.stripe.model.Token stripeToken = com.stripe.model.Token.retrieve( - tokenId, publishableKey); + tokenId); com.stripe.model.Card stripeCard = stripeToken.getCard(); Card card = androidCardFromStripeCard(stripeCard); Token token = androidTokenFromStripeToken(card, stripeToken); @@ -62,12 +59,13 @@ protected ResponseWrapper doInBackground(Void... params) { protected void onPostExecute(ResponseWrapper result) { tokenTaskPostExecution(result, callback); - } + } }; executeTokenTask(executor, task); - } + } }; + private String defaultPublishableKey; public Stripe() { } @@ -83,10 +81,10 @@ public void setDefaultPublishableKey(String publishableKey) throws Authenticatio private void validateKey(String publishableKey) throws AuthenticationException { if (publishableKey == null || publishableKey.length() == 0) { - throw new AuthenticationException("Invalid Publishable Key: You must use a valid publishable key to create a token. For more info, see https://stripe.com/docs/stripe.js."); + throw new AuthenticationException("Invalid Publishable Key: You must use a valid publishable key to create a token. For more info, see https://stripe.com/docs/stripe.js.", "", "", 0); } if (publishableKey.startsWith("sk_")) { - throw new AuthenticationException("Invalid Publishable Key: You are using a secret key to create a token, instead of the publishable one. For more info, see https://stripe.com/docs/stripe.js"); + throw new AuthenticationException("Invalid Publishable Key: You are using a secret key to create a token, instead of the publishable one. For more info, see https://stripe.com/docs/stripe.js", "", "", 0); } } @@ -113,8 +111,7 @@ public void requestToken(final String tokenId, final String publishableKey, fina validateKey(publishableKey); tokenRequester.request(tokenId, publishableKey, executor, callback); - } - catch (AuthenticationException e) { + } catch (AuthenticationException e) { callback.onError(e); } } @@ -142,14 +139,18 @@ public void createToken(final Card card, final String publishableKey, final Exec validateKey(publishableKey); tokenCreator.create(card, publishableKey, executor, callback); - } - catch (AuthenticationException e) { + } catch (AuthenticationException e) { callback.onError(e); } } private Card androidCardFromStripeCard(com.stripe.model.Card stripeCard) { - return new Card(null, stripeCard.getExpMonth(), stripeCard.getExpYear(), null, stripeCard.getName(), stripeCard.getAddressLine1(), stripeCard.getAddressLine2(), stripeCard.getAddressCity(), stripeCard.getAddressState(), stripeCard.getAddressZip(), stripeCard.getAddressCountry(), stripeCard.getLast4(), stripeCard.getType(), stripeCard.getFingerprint(), stripeCard.getCountry()); + return new Card(null, stripeCard.getExpMonth(), stripeCard.getExpYear(), null, + stripeCard.getName(), stripeCard.getAddressLine1(), stripeCard.getAddressLine2(), + stripeCard.getAddressCity(), stripeCard.getAddressState(), stripeCard.getAddressZip(), + stripeCard.getAddressCountry(), stripeCard.getLast4(), "", + stripeCard.getFingerprint(), stripeCard.getCountry() + ); } private Token androidTokenFromStripeToken(Card androidCard, com.stripe.model.Token stripeToken) { @@ -199,6 +200,14 @@ private Map hashMapFromCard(Card card) { return tokenParams; } + interface TokenCreator { + void create(Card card, String publishableKey, Executor executor, TokenCallback callback); + } + + interface TokenRequester { + void request(String tokenId, String publishableKey, Executor executor, TokenCallback callback); + } + private class ResponseWrapper { public final Token token; public final Exception error; @@ -208,12 +217,4 @@ private ResponseWrapper(Token token, Exception error) { this.token = token; } } - - interface TokenCreator { - public void create(Card card, String publishableKey, Executor executor, TokenCallback callback); - } - - interface TokenRequester { - public void request(String tokenId, String publishableKey, Executor executor, TokenCallback callback); - } -} \ No newline at end of file +} diff --git a/stripe_android/android/src/com/stripe/android/model/Card.java b/stripe_android/android/src/com/stripe/android/model/Card.java index e484e30..3d32390 100755 --- a/stripe_android/android/src/com/stripe/android/model/Card.java +++ b/stripe_android/android/src/com/stripe/android/model/Card.java @@ -26,8 +26,8 @@ public class Card extends com.stripe.model.StripeObject { private String number; private String cvc; - private Integer expMonth; - private Integer expYear; + private Long expMonth; + private Long expYear; private String name; private String addressLine1; private String addressLine2; @@ -43,8 +43,8 @@ public class Card extends com.stripe.model.StripeObject { public static class Builder { private final String number; private final String cvc; - private final Integer expMonth; - private final Integer expYear; + private final Long expMonth; + private final Long expYear; private String name; private String addressLine1; private String addressLine2; @@ -57,7 +57,7 @@ public static class Builder { private String fingerprint; private String country; - public Builder(String number, Integer expMonth, Integer expYear, String cvc) { + public Builder(String number, Long expMonth, Long expYear, String cvc) { this.number = number; this.expMonth = expMonth; this.expYear = expYear; @@ -144,7 +144,7 @@ private Card(Builder builder) { this.last4 = getLast4(); } - public Card(String number, Integer expMonth, Integer expYear, String cvc, String name, String addressLine1, String addressLine2, String addressCity, String addressState, String addressZip, String addressCountry, String last4, String type, String fingerprint, String country) { + public Card(String number, Long expMonth, Long expYear, String cvc, String name, String addressLine1, String addressLine2, String addressCity, String addressState, String addressZip, String addressCountry, String last4, String type, String fingerprint, String country) { this.number = TextUtils.nullIfBlank(normalizeCardNumber(number)); this.expMonth = expMonth; this.expYear = expYear; @@ -164,11 +164,11 @@ public Card(String number, Integer expMonth, Integer expYear, String cvc, String this.last4 = getLast4(); } - public Card(String number, Integer expMonth, Integer expYear, String cvc, String name, String addressLine1, String addressLine2, String addressCity, String addressState, String addressZip, String addressCountry) { + public Card(String number, Long expMonth, Long expYear, String cvc, String name, String addressLine1, String addressLine2, String addressCity, String addressState, String addressZip, String addressCountry) { this(number, expMonth, expYear, cvc, name, addressLine1, addressLine2, addressCity, addressState, addressZip, addressCountry, null, null, null, null); } - public Card(String number, Integer expMonth, Integer expYear, String cvc) { + public Card(String number, Long expMonth, Long expYear, String cvc) { this(number, expMonth, expYear, cvc, null, null, null, null, null, null, null, null, null, null, null); } @@ -208,7 +208,7 @@ public boolean validateExpiryDate() { if (!validateExpYear()) { return false; } - return !DateUtils.hasMonthPassed(expYear, expMonth); + return !DateUtils.hasMonthPassed(Math.toIntExact(expYear), Math.toIntExact(expMonth)); } public boolean validateExpMonth() { @@ -222,7 +222,7 @@ public boolean validateExpYear() { if (expYear == null) { return false; } - return !DateUtils.hasYearPassed(expYear); + return !DateUtils.hasYearPassed(Math.toIntExact(expYear)); } public boolean validateCVC() { @@ -290,19 +290,19 @@ public void setCVC(String cvc) { this.cvc = cvc; } - public Integer getExpMonth() { + public Long getExpMonth() { return expMonth; } - public void setExpMonth(Integer expMonth) { + public void setExpMonth(Long expMonth) { this.expMonth = expMonth; } - public Integer getExpYear() { + public Long getExpYear() { return expYear; } - public void setExpYear(Integer expYear) { + public void setExpYear(Long expYear) { this.expYear = expYear; }