Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get scanned Image path and scanned image URL (IOS Only) #78

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
24 changes: 22 additions & 2 deletions ios/RCTCardIOModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the file name doesn't seem to be unique, is it meant to be a temporary location?

[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],
Expand All @@ -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]
});
}

Expand Down