From e0bc9c98addb47a561dd859308bc765972067d5f Mon Sep 17 00:00:00 2001 From: Dina Ashraf Date: Mon, 4 Dec 2017 10:05:46 +0200 Subject: [PATCH 01/14] get image path and url ios --- ios/RCTCardIOModule.m | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/ios/RCTCardIOModule.m b/ios/RCTCardIOModule.m index 07eeb933..de8e0280 100644 --- a/ios/RCTCardIOModule.m +++ b/ios/RCTCardIOModule.m @@ -122,11 +122,29 @@ - (void)userDidCancelPaymentViewController:(CardIOPaymentViewController *)scanVi _reject(@"user_cancelled", @"The user cancelled", nil); } +- (NSString *)documentsPathForFileName:(NSString *)name +{ + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); + NSString *documentsPath = [paths objectAtIndex:0]; + + return [documentsPath stringByAppendingPathComponent:name]; +} + +- (NSString *)saveScannedImageToDocumentsDirectory:(UIImage *)scannedImage { + NSData* imageData = UIImagePNGRepresentation(scannedImage); + NSString *filePath = [self documentsPathForFileName:@"scannedImage.png"]; //Add the file name + [imageData writeToFile:filePath atomically:YES]; //Write the file + return filePath; +} + - (void)userDidProvideCreditCardInfo:(CardIOCreditCardInfo *)cardInfo inPaymentViewController:(CardIOPaymentViewController *)scanViewController { [scanViewController dismissViewControllerAnimated:YES completion:nil]; NSString *cardType = [CardIOCreditCardInfo displayStringForCardType:cardInfo.cardType usingLanguageOrLocale:scanViewController.languageOrLocale]; - + NSString *filePath = [self saveScannedImageToDocumentsDirectory:cardInfo.cardImage]; + NSURL *filePathURL = [NSURL fileURLWithPath:filePath]; + NSString *filePathURLStr = filePathURL.absoluteString; + _resolve(@{ @"cardType": cardType, @"cardNumber": cardInfo.cardNumber ?: [NSNull null], @@ -136,7 +154,9 @@ - (void)userDidProvideCreditCardInfo:(CardIOCreditCardInfo *)cardInfo inPaymentV @"cvv": cardInfo.cvv ?: [NSNull null], @"postalCode": cardInfo.postalCode ?: [NSNull null], @"scanned": @(cardInfo.scanned), - @"cardholderName": cardInfo.cardholderName ?: [NSNull null] + @"cardholderName": cardInfo.cardholderName ?: [NSNull null], + @"scannedImagePath": filePath ?: [NSNull null], + @"scannedImageURL": filePathURLStr ?: [NSNull null] }); } From 0f3efff1dfe048032fb5f1c3d7511f3fb3bba388 Mon Sep 17 00:00:00 2001 From: MinaSedrak Date: Tue, 5 Dec 2017 19:25:28 +0200 Subject: [PATCH 02/14] test --- android/src/main/java/com/cardio/RNCardIOModule.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/android/src/main/java/com/cardio/RNCardIOModule.java b/android/src/main/java/com/cardio/RNCardIOModule.java index c6b45170..1533a362 100644 --- a/android/src/main/java/com/cardio/RNCardIOModule.java +++ b/android/src/main/java/com/cardio/RNCardIOModule.java @@ -3,6 +3,7 @@ import android.app.Activity; import android.content.Intent; import android.graphics.Color; +import java.utils.Log; import com.facebook.react.bridge.ActivityEventListener; import com.facebook.react.bridge.Arguments; @@ -25,6 +26,8 @@ public class RNCardIOModule extends ReactContextBaseJavaModule implements Activi public RNCardIOModule(ReactApplicationContext reactContext) { super(reactContext); reactContext.addActivityEventListener(this); + + Log.i('Test'); } @Override From 48add7a46b02a3fcb9b06878ca344c8689b5b59c Mon Sep 17 00:00:00 2001 From: MinaSedrak Date: Tue, 5 Dec 2017 19:27:34 +0200 Subject: [PATCH 03/14] remove test --- android/src/main/java/com/cardio/RNCardIOModule.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/android/src/main/java/com/cardio/RNCardIOModule.java b/android/src/main/java/com/cardio/RNCardIOModule.java index 1533a362..ad0025d4 100644 --- a/android/src/main/java/com/cardio/RNCardIOModule.java +++ b/android/src/main/java/com/cardio/RNCardIOModule.java @@ -3,7 +3,6 @@ import android.app.Activity; import android.content.Intent; import android.graphics.Color; -import java.utils.Log; import com.facebook.react.bridge.ActivityEventListener; import com.facebook.react.bridge.Arguments; @@ -27,7 +26,6 @@ public RNCardIOModule(ReactApplicationContext reactContext) { super(reactContext); reactContext.addActivityEventListener(this); - Log.i('Test'); } @Override From f006ae3b8a33a72089a39b3fba7d78f8b3789db7 Mon Sep 17 00:00:00 2001 From: Developer Date: Wed, 20 Dec 2017 13:49:07 +0200 Subject: [PATCH 04/14] remove space --- android/src/main/java/com/cardio/RNCardIOModule.java | 1 - 1 file changed, 1 deletion(-) diff --git a/android/src/main/java/com/cardio/RNCardIOModule.java b/android/src/main/java/com/cardio/RNCardIOModule.java index ad0025d4..c6b45170 100644 --- a/android/src/main/java/com/cardio/RNCardIOModule.java +++ b/android/src/main/java/com/cardio/RNCardIOModule.java @@ -25,7 +25,6 @@ public class RNCardIOModule extends ReactContextBaseJavaModule implements Activi public RNCardIOModule(ReactApplicationContext reactContext) { super(reactContext); reactContext.addActivityEventListener(this); - } @Override From 2e08cdcde861ee0ac0a3744a1eaf58619b872133 Mon Sep 17 00:00:00 2001 From: Mina Sedrak Date: Mon, 15 Jan 2018 15:56:59 +0200 Subject: [PATCH 05/14] Update CardIOModule --- .../main/java/com/cardio/RNCardIOModule.java | 57 +++++++++++++++---- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/android/src/main/java/com/cardio/RNCardIOModule.java b/android/src/main/java/com/cardio/RNCardIOModule.java index c6b45170..bbefdbf8 100644 --- a/android/src/main/java/com/cardio/RNCardIOModule.java +++ b/android/src/main/java/com/cardio/RNCardIOModule.java @@ -16,6 +16,14 @@ import io.card.payment.CardIOActivity; import io.card.payment.CreditCard; +import android.content.ContextWrapper; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; + + public class RNCardIOModule extends ReactContextBaseJavaModule implements ActivityEventListener { public static final int CARD_IO_SCAN = 1; @@ -37,8 +45,12 @@ public void scanCard(ReadableMap config, Promise promise) { this.promise = promise; Activity activity = getCurrentActivity(); Intent scanIntent = new Intent(activity, CardIOActivity.class); - scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_EXPIRY, true); - scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_CVV, true); + //scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_EXPIRY, true); + //scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_CVV, true); + scanIntent.putExtra(CardIOActivity.EXTRA_SCAN_RESULT, true); + scanIntent.putExtra(CardIOActivity.EXTRA_CAPTURED_CARD_IMAGE, true); + scanIntent.putExtra(CardIOActivity.EXTRA_RETURN_CARD_IMAGE, true); + parseConfig(config, scanIntent); if (activity != null) { activity.startActivityForResult(scanIntent, CARD_IO_SCAN); @@ -97,6 +109,9 @@ public void parseConfig(ReadableMap config, Intent intent) { if (config.hasKey("usePaypalActionbarIcon")) { intent.putExtra(CardIOActivity.EXTRA_USE_PAYPAL_ACTIONBAR_ICON, config.getBoolean("usePaypalActionbarIcon")); } + if (config.hasKey("borderImageOnly")) { + intent.putExtra(CardIOActivity.EXTRA_SUPPRESS_SCAN, config.getBoolean("borderImageOnly")); + } } @Override @@ -104,17 +119,35 @@ public void onActivityResult(Activity activity, int requestCode, int resultCode, if (requestCode != CARD_IO_SCAN) { return; } - if (data != null && data.hasExtra(CardIOActivity.EXTRA_SCAN_RESULT)) { - CreditCard scanResult = data.getParcelableExtra(CardIOActivity.EXTRA_SCAN_RESULT); + if (data != null ) { + + Bitmap resultCard = CardIOActivity.getCapturedCardImage(data); + + ContextWrapper wrapper = new ContextWrapper(getApplicationContext()); + File newImageFile = wrapper.getDir("images",MODE_PRIVATE); + newImageFile = new File(newImageFile, "detectedCardImage"+ ".jpg"); + try { + OutputStream outputStream = new FileOutputStream(newImageFile); + resultCard.compress(Bitmap.CompressFormat.JPEG,100,outputStream); + outputStream.flush(); + outputStream.close(); + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + WritableMap res = Arguments.createMap(); - res.putString("cardType", scanResult.getCardType().getDisplayName(data.getStringExtra(CardIOActivity.EXTRA_LANGUAGE_OR_LOCALE))); - res.putString("cardNumber", scanResult.cardNumber); - res.putString("redactedCardNumber", scanResult.getRedactedCardNumber()); - res.putInt("expiryMonth", scanResult.expiryMonth); - res.putInt("expiryYear", scanResult.expiryYear); - res.putString("cvv", scanResult.cvv); - res.putString("postalCode", scanResult.postalCode); - res.putString("cardholderName", scanResult.cardholderName); + res.putString("imagePath", newImageFile.getAbsolutePath()); +// res.putString("cardNumber", scanResult.cardNumber); +// res.putString("redactedCardNumber", scanResult.getRedactedCardNumber()); +// res.putInt("expiryMonth", scanResult.expiryMonth); +// res.putInt("expiryYear", scanResult.expiryYear); +// res.putString("cvv", scanResult.cvv); +// res.putString("postalCode", scanResult.postalCode); +// res.putString("cardholderName", scanResult.cardholderName); promise.resolve(res); } else { promise.reject("user_cancelled", "The user cancelled"); From 2c16f8102e4d29347ceea96087e4b4496cb818d0 Mon Sep 17 00:00:00 2001 From: Mina Sedrak Date: Mon, 15 Jan 2018 15:57:52 +0200 Subject: [PATCH 06/14] remove ScanResult Flag --- android/src/main/java/com/cardio/RNCardIOModule.java | 1 - 1 file changed, 1 deletion(-) diff --git a/android/src/main/java/com/cardio/RNCardIOModule.java b/android/src/main/java/com/cardio/RNCardIOModule.java index bbefdbf8..9cb833f9 100644 --- a/android/src/main/java/com/cardio/RNCardIOModule.java +++ b/android/src/main/java/com/cardio/RNCardIOModule.java @@ -47,7 +47,6 @@ public void scanCard(ReadableMap config, Promise promise) { Intent scanIntent = new Intent(activity, CardIOActivity.class); //scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_EXPIRY, true); //scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_CVV, true); - scanIntent.putExtra(CardIOActivity.EXTRA_SCAN_RESULT, true); scanIntent.putExtra(CardIOActivity.EXTRA_CAPTURED_CARD_IMAGE, true); scanIntent.putExtra(CardIOActivity.EXTRA_RETURN_CARD_IMAGE, true); From 4612ca21425c0d062d31c1f6699906e5f5e9d9be Mon Sep 17 00:00:00 2001 From: Mina Sedrak Date: Mon, 15 Jan 2018 16:32:20 +0200 Subject: [PATCH 07/14] add android.graphics.Bitmap --- android/src/main/java/com/cardio/RNCardIOModule.java | 1 + 1 file changed, 1 insertion(+) diff --git a/android/src/main/java/com/cardio/RNCardIOModule.java b/android/src/main/java/com/cardio/RNCardIOModule.java index 9cb833f9..eda14a49 100644 --- a/android/src/main/java/com/cardio/RNCardIOModule.java +++ b/android/src/main/java/com/cardio/RNCardIOModule.java @@ -16,6 +16,7 @@ import io.card.payment.CardIOActivity; import io.card.payment.CreditCard; +import android.graphics.Bitmap; import android.content.ContextWrapper; import java.io.File; import java.io.FileNotFoundException; From 5822be416ae45082d9c084841adf6ef5f85ce095 Mon Sep 17 00:00:00 2001 From: Mina Sedrak Date: Mon, 15 Jan 2018 16:45:41 +0200 Subject: [PATCH 08/14] remove ModePrivate --- android/src/main/java/com/cardio/RNCardIOModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/src/main/java/com/cardio/RNCardIOModule.java b/android/src/main/java/com/cardio/RNCardIOModule.java index eda14a49..fada0824 100644 --- a/android/src/main/java/com/cardio/RNCardIOModule.java +++ b/android/src/main/java/com/cardio/RNCardIOModule.java @@ -124,7 +124,7 @@ public void onActivityResult(Activity activity, int requestCode, int resultCode, Bitmap resultCard = CardIOActivity.getCapturedCardImage(data); ContextWrapper wrapper = new ContextWrapper(getApplicationContext()); - File newImageFile = wrapper.getDir("images",MODE_PRIVATE); + File newImageFile = wrapper.getDir("images",0); newImageFile = new File(newImageFile, "detectedCardImage"+ ".jpg"); try { OutputStream outputStream = new FileOutputStream(newImageFile); From fb42b3a9ca93b75f091b62e9e7699404a4cf54df Mon Sep 17 00:00:00 2001 From: Mina Sedrak Date: Mon, 15 Jan 2018 16:52:12 +0200 Subject: [PATCH 09/14] update context --- android/src/main/java/com/cardio/RNCardIOModule.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/cardio/RNCardIOModule.java b/android/src/main/java/com/cardio/RNCardIOModule.java index fada0824..82f91d45 100644 --- a/android/src/main/java/com/cardio/RNCardIOModule.java +++ b/android/src/main/java/com/cardio/RNCardIOModule.java @@ -30,9 +30,11 @@ public class RNCardIOModule extends ReactContextBaseJavaModule implements Activi public static final int CARD_IO_SCAN = 1; private Promise promise; + private ReactApplicationContext mReactContext; public RNCardIOModule(ReactApplicationContext reactContext) { super(reactContext); + mReactContext = reactContext; reactContext.addActivityEventListener(this); } @@ -123,7 +125,7 @@ public void onActivityResult(Activity activity, int requestCode, int resultCode, Bitmap resultCard = CardIOActivity.getCapturedCardImage(data); - ContextWrapper wrapper = new ContextWrapper(getApplicationContext()); + ContextWrapper wrapper = new ContextWrapper(mReactContext); File newImageFile = wrapper.getDir("images",0); newImageFile = new File(newImageFile, "detectedCardImage"+ ".jpg"); try { From 05c681019b6a9a4bb7561e6de7dc19431570e1c1 Mon Sep 17 00:00:00 2001 From: Mina Sedrak Date: Tue, 16 Jan 2018 10:49:01 +0200 Subject: [PATCH 10/14] Update CardModule --- .../src/main/java/com/cardio/RNCardIOModule.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/android/src/main/java/com/cardio/RNCardIOModule.java b/android/src/main/java/com/cardio/RNCardIOModule.java index 82f91d45..4b8b7bb4 100644 --- a/android/src/main/java/com/cardio/RNCardIOModule.java +++ b/android/src/main/java/com/cardio/RNCardIOModule.java @@ -143,13 +143,13 @@ public void onActivityResult(Activity activity, int requestCode, int resultCode, WritableMap res = Arguments.createMap(); res.putString("imagePath", newImageFile.getAbsolutePath()); -// res.putString("cardNumber", scanResult.cardNumber); -// res.putString("redactedCardNumber", scanResult.getRedactedCardNumber()); -// res.putInt("expiryMonth", scanResult.expiryMonth); -// res.putInt("expiryYear", scanResult.expiryYear); -// res.putString("cvv", scanResult.cvv); -// res.putString("postalCode", scanResult.postalCode); -// res.putString("cardholderName", scanResult.cardholderName); + res.putString("cardNumber", scanResult.cardNumber); + res.putString("redactedCardNumber", scanResult.getRedactedCardNumber()); + res.putInt("expiryMonth", scanResult.expiryMonth); + res.putInt("expiryYear", scanResult.expiryYear); + res.putString("cvv", scanResult.cvv); + res.putString("postalCode", scanResult.postalCode); + res.putString("cardholderName", scanResult.cardholderName); promise.resolve(res); } else { promise.reject("user_cancelled", "The user cancelled"); From f09164fe3304e46d80d85d6504595fdbdf8aaa90 Mon Sep 17 00:00:00 2001 From: Mina Sedrak Date: Tue, 16 Jan 2018 10:52:41 +0200 Subject: [PATCH 11/14] rename imagePath --- android/src/main/java/com/cardio/RNCardIOModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/src/main/java/com/cardio/RNCardIOModule.java b/android/src/main/java/com/cardio/RNCardIOModule.java index 4b8b7bb4..e00afa30 100644 --- a/android/src/main/java/com/cardio/RNCardIOModule.java +++ b/android/src/main/java/com/cardio/RNCardIOModule.java @@ -142,7 +142,7 @@ public void onActivityResult(Activity activity, int requestCode, int resultCode, WritableMap res = Arguments.createMap(); - res.putString("imagePath", newImageFile.getAbsolutePath()); + res.putString("scannedImagePath", newImageFile.getAbsolutePath()); res.putString("cardNumber", scanResult.cardNumber); res.putString("redactedCardNumber", scanResult.getRedactedCardNumber()); res.putInt("expiryMonth", scanResult.expiryMonth); From 050f4878836f989ada0a41ae1c2a86484c53e29e Mon Sep 17 00:00:00 2001 From: Mina Sedrak Date: Tue, 16 Jan 2018 11:58:23 +0200 Subject: [PATCH 12/14] add scanResult --- android/src/main/java/com/cardio/RNCardIOModule.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/android/src/main/java/com/cardio/RNCardIOModule.java b/android/src/main/java/com/cardio/RNCardIOModule.java index e00afa30..fb32a3b2 100644 --- a/android/src/main/java/com/cardio/RNCardIOModule.java +++ b/android/src/main/java/com/cardio/RNCardIOModule.java @@ -122,6 +122,7 @@ public void onActivityResult(Activity activity, int requestCode, int resultCode, return; } if (data != null ) { + Bitmap resultCard = CardIOActivity.getCapturedCardImage(data); @@ -140,6 +141,7 @@ public void onActivityResult(Activity activity, int requestCode, int resultCode, e.printStackTrace(); } + CreditCard scanResult = data.getParcelableExtra(CardIOActivity.EXTRA_SCAN_RESULT); WritableMap res = Arguments.createMap(); res.putString("scannedImagePath", newImageFile.getAbsolutePath()); From 09ac99f64288db932471c0376d0b0862e699d8ff Mon Sep 17 00:00:00 2001 From: dinaashraf Date: Fri, 29 Mar 2019 17:32:23 +0200 Subject: [PATCH 13/14] update CardIoModule --- .../src/main/java/com/cardio/RNCardIOModule.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/android/src/main/java/com/cardio/RNCardIOModule.java b/android/src/main/java/com/cardio/RNCardIOModule.java index fb32a3b2..0dc08288 100644 --- a/android/src/main/java/com/cardio/RNCardIOModule.java +++ b/android/src/main/java/com/cardio/RNCardIOModule.java @@ -141,17 +141,17 @@ public void onActivityResult(Activity activity, int requestCode, int resultCode, e.printStackTrace(); } - CreditCard scanResult = data.getParcelableExtra(CardIOActivity.EXTRA_SCAN_RESULT); +// CreditCard scanResult = data.getParcelableExtra(CardIOActivity.EXTRA_SCAN_RESULT); WritableMap res = Arguments.createMap(); res.putString("scannedImagePath", newImageFile.getAbsolutePath()); - res.putString("cardNumber", scanResult.cardNumber); - res.putString("redactedCardNumber", scanResult.getRedactedCardNumber()); - res.putInt("expiryMonth", scanResult.expiryMonth); - res.putInt("expiryYear", scanResult.expiryYear); - res.putString("cvv", scanResult.cvv); - res.putString("postalCode", scanResult.postalCode); - res.putString("cardholderName", scanResult.cardholderName); +// res.putString("cardNumber", scanResult.cardNumber); +// res.putString("redactedCardNumber", scanResult.getRedactedCardNumber()); +// res.putInt("expiryMonth", scanResult.expiryMonth); +// res.putInt("expiryYear", scanResult.expiryYear); +// res.putString("cvv", scanResult.cvv); +// res.putString("postalCode", scanResult.postalCode); +// res.putString("cardholderName", scanResult.cardholderName); promise.resolve(res); } else { promise.reject("user_cancelled", "The user cancelled"); From 30039bcb75c2c11cfe1b07994a6666c2b19367e8 Mon Sep 17 00:00:00 2001 From: dinaashraf Date: Mon, 30 Dec 2019 16:16:04 +0200 Subject: [PATCH 14/14] fullscreen modal view --- ios/RCTCardIOModule.m | 1 + 1 file changed, 1 insertion(+) diff --git a/ios/RCTCardIOModule.m b/ios/RCTCardIOModule.m index de8e0280..94301b59 100644 --- a/ios/RCTCardIOModule.m +++ b/ios/RCTCardIOModule.m @@ -114,6 +114,7 @@ - (void)parseConfig:(NSDictionary *)config viewController:(CardIOPaymentViewCont [self parseConfig:config viewController:scanViewController]; UIViewController *rootViewController = RCTPresentedViewController(); + scanViewController.modalPresentationStyle = UIModalPresentationFullScreen; [rootViewController presentViewController:scanViewController animated:YES completion:nil]; }