Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
489b61e
Create confirmCardSetup function in GatewayManager for confirming set…
runticle Nov 13, 2020
ad2460e
Add authenticationPresentingViewController to GatewayManager
runticle Nov 13, 2020
317a1da
Add confirmCardSetup function and export as part of Intents object
runticle Nov 13, 2020
8d0e1f9
Oopsie forgot to import Platform
runticle Nov 13, 2020
77310b0
Import RCTConvert
runticle Nov 13, 2020
5e17a24
Rename confirmCardSetup to savePaymentMethod
runticle Nov 13, 2020
3be33db
Rename secret to clientSecret and export savePaymendMethod function f…
runticle Nov 13, 2020
84759a7
silly bugfix in eslintrc
nabilfreeman Nov 13, 2020
9ce2185
export * as intents
nabilfreeman Nov 13, 2020
d7f55b1
Rename names back to stripe names other than when exporting the NAtiv…
runticle Nov 13, 2020
d961509
Merge branch 'master' into add-setup-intents
runticle Nov 13, 2020
02ef228
upgrade android play services version and add stripe SDK to android
nabilfreeman Nov 13, 2020
203ac38
Merge branch 'add-setup-intents' of https://github.com/freeman-indust…
nabilfreeman Nov 13, 2020
6671024
Add confirmPayment functionality
runticle Nov 13, 2020
3464a7e
Some bug fixes
runticle Nov 13, 2020
ccaf265
fix intent thing
nabilfreeman Nov 13, 2020
89db3f3
Merge branch 'add-setup-intents' of https://github.com/freeman-indust…
nabilfreeman Nov 13, 2020
77e283b
Fix exoprts like this for now
runticle Nov 13, 2020
9963e40
Bad merge lol
runticle Nov 13, 2020
f860eaa
remove react native from dev dependencies (frustrating for local deve…
nabilfreeman Nov 13, 2020
2e3f809
Merge branch 'add-setup-intents' of https://github.com/freeman-indust…
nabilfreeman Nov 13, 2020
323ae60
traaaavis install react native as a peer dep
nabilfreeman Nov 13, 2020
a521ae3
Revert "upgrade android play services version and add stripe SDK to a…
nabilfreeman Nov 15, 2020
959438f
works with stripe 15, not 16!!
nabilfreeman Nov 15, 2020
0341443
change directory path
nabilfreeman Nov 15, 2020
3ae94ed
raaah
nabilfreeman Nov 15, 2020
0cc9397
IGNORE android studio crap
nabilfreeman Nov 15, 2020
86603e3
first part of gateway manager works!!!!!
nabilfreeman Nov 15, 2020
83d6410
add gateway manager import and group other imports a bit more
nabilfreeman Nov 15, 2020
cf21b32
add savePaymentMethod to Android
nabilfreeman Nov 15, 2020
42fa50c
stripe gateway can now be configured in Android
nabilfreeman Nov 15, 2020
5dddeb2
bug fixes
nabilfreeman Nov 15, 2020
0ac9578
protect against non string values in card params
nabilfreeman Nov 17, 2020
740148f
sanitize inputs and support billing details and metadata
nabilfreeman Nov 17, 2020
ba35163
reindent xcode files
nabilfreeman Nov 17, 2020
0310ec9
thanks xcode
nabilfreeman Nov 17, 2020
6ff4597
add billing details and metadata to setup intent
nabilfreeman Nov 17, 2020
ee419a2
disable extra fields to payment methods, just too much to deal with c…
nabilfreeman Nov 17, 2020
3842941
initialize gateway manager
nabilfreeman Nov 17, 2020
2c4aec2
activate savePaymentMethod for android so we can see what happens
nabilfreeman Nov 17, 2020
a361c3c
bad variable (and add a callback)
nabilfreeman Nov 17, 2020
f07cffa
convert error message into a real error on rejection
nabilfreeman Nov 18, 2020
3087599
delete all the examples they are getting in the way
nabilfreeman Nov 19, 2020
4d2910c
Fix imports
runticle Nov 19, 2020
ca35981
Sanitise params for confirmPayment
runticle Nov 19, 2020
1034bf7
Mock ReactNative for the Intents tests
runticle Nov 19, 2020
9fd58eb
Test Intents functions
runticle Nov 19, 2020
23f6af5
vscode format
nabilfreeman Nov 19, 2020
2c7014a
finallly starting to understand
nabilfreeman Nov 20, 2020
420058e
delete billingdata and metadata
nabilfreeman Nov 20, 2020
7618193
move gatewaymanager stuff to ReactNativePaymentsModule, really strugg…
nabilfreeman Nov 20, 2020
ef8512f
write confirmSetupIntent into ReactNativePaymentsModule
nabilfreeman Nov 20, 2020
ca7ba25
add stripe callback variable and event listener
nabilfreeman Nov 20, 2020
c1be5a0
will
nabilfreeman Nov 20, 2020
f815bd3
write the onActivityResult handler for stripe (might have to merge th…
nabilfreeman Nov 20, 2020
7ccb975
please god let it be over
nabilfreeman Nov 20, 2020
16bb8aa
IT BUILDS!!!
nabilfreeman Nov 20, 2020
ee115f6
please let this be it
nabilfreeman Nov 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ios/GatewayManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
merchantIdentifier:(NSString *_Nonnull)merchantId;
- (void)createStripeTokenWithPayment:(PKPayment *_Nonnull)payment
completion:(void (^_Nullable)(NSString * _Nullable token, NSError * _Nullable error))completion;
- (void)savePaymentMethod:secret cardParams:cardParams completion:(void (^_Nullable)(NSString * _Nullable token, NSError * _Nullable error))completion;

// Braintree
- (void)configureBraintreeGateway:(NSDictionary *_Nonnull)gatewayParameters;
Expand Down
45 changes: 45 additions & 0 deletions ios/GatewayManager.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import "GatewayManager.h"
#import <React/RCTConvert.h>

#if __has_include(<Stripe/Stripe.h>)
#import <Stripe/Stripe.h>
Expand Down Expand Up @@ -64,6 +65,45 @@ - (void)configureStripeGateway:(NSDictionary *_Nonnull)gatewayParameters
#endif
}


- (void)savePaymentMethod:(NSString *)clientSecret cardParams:(NSDictionary *)cardParams completion:(void (^)(NSString * _Nullable, NSError * _Nullable))completion
{
#if __has_include(<Stripe/Stripe.h>)
// Collect card details
STPPaymentMethodCardParams *card = [[STPPaymentMethodCardParams alloc] init];
card.number = [RCTConvert NSString:cardParams[@"number"]];
card.expYear = [RCTConvert NSNumber:cardParams[@"expYear"]];
card.expMonth = [RCTConvert NSNumber:cardParams[@"expMonth"]];
card.cvc = [RCTConvert NSString:cardParams[@"cvc"]];
STPPaymentMethodParams *paymentMethodParams = [STPPaymentMethodParams paramsWithCard:card billingDetails:nil metadata:nil];
Copy link
Member

Choose a reason for hiding this comment

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

Maybe here, paramsWithCard could potentially be paramsWithToken

Copy link
Contributor Author

Choose a reason for hiding this comment

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

STPSetupIntentConfirmParams *setupIntentParams = [[STPSetupIntentConfirmParams alloc] initWithClientSecret:clientSecret];
setupIntentParams.paymentMethodParams = paymentMethodParams;

// Confirm setup intent (authorize use of paymend method for future payments)
STPPaymentHandler *paymentHandler = [STPPaymentHandler sharedHandler];
[paymentHandler confirmSetupIntent:(STPSetupIntentConfirmParams *)setupIntentParams withAuthenticationContext:self completion:^(STPPaymentHandlerActionStatus status, STPSetupIntent *setupIntent, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
switch (status) {
case STPPaymentHandlerActionStatusFailed: {
completion(nil, error);
break;
}
case STPPaymentHandlerActionStatusCanceled: {
completion(nil, error);
break;
}
case STPPaymentHandlerActionStatusSucceeded: {
completion(setupIntent.paymentMethodID, nil);
Copy link
Member

Choose a reason for hiding this comment

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

Nice, so we have validated that we can get the method ID out of this method

break;
}
default:
break;
}
});
}];
#endif
}

- (void)createStripeTokenWithPayment:(PKPayment *)payment completion:(void (^)(NSString * _Nullable, NSError * _Nullable))completion
{
#if __has_include(<Stripe/Stripe.h>)
Expand Down Expand Up @@ -111,4 +151,9 @@ - (void)createBraintreeTokenWithPayment:(PKPayment *_Nonnull)payment
#endif
}

- (UIViewController *)authenticationPresentingViewController
{
return RCTPresentedViewController();
}

@end
31 changes: 31 additions & 0 deletions ios/ReactNativePayments.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,37 @@ - (NSDictionary *)constantsToExport
callback(@[[NSNull null]]);
}


RCT_EXPORT_METHOD(savePaymentMethod: (NSDictionary *)methodData
cardParams: (NSDictionary *)cardParams
callback: (RCTResponseSenderBlock)callback)
{
NSString *merchantId = methodData[@"merchantIdentifier"];
Copy link
Member

Choose a reason for hiding this comment

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

merchantId is pk_test_... right?

NSDictionary *gatewayParameters = methodData[@"paymentMethodTokenizationParameters"][@"parameters"];

NSLog(@"%@", gatewayParameters);

if (gatewayParameters) {
self.hasGatewayParameters = true;
self.gatewayManager = [GatewayManager new];
[self.gatewayManager configureGateway:gatewayParameters merchantIdentifier:merchantId];
}

if (self.hasGatewayParameters) {
[self.gatewayManager savePaymentMethod:methodData[@"clientSecret"] cardParams:cardParams completion:^(NSString * _Nullable token, NSError * _Nullable error) {
if (error) {
NSLog(@"Failed");
NSLog(@"%@", error);
NSString *message = error.localizedDescription;
callback(@[message, [NSNull null]]);
return;
}

callback(@[[NSNull null], token]);
}];
}
}

RCT_EXPORT_METHOD(show:(RCTResponseSenderBlock)callback)
{

Expand Down
27 changes: 27 additions & 0 deletions js/Intents/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { NativeModules, Platform } from 'react-native';

const { ReactNativePayments } = NativeModules;

const IS_ANDROID = Platform.OS === 'android';

const Intents = {
savePaymentMethod(methodData, cardParams) {
return new Promise((resolve, reject) => {
if (IS_ANDROID) {
return resolve();
}

ReactNativePayments.savePaymentMethod(
methodData,
cardParams,
(err, data) => {
if (err) return reject(err);

resolve(data);
}
);
});
}
}

export { Intents };
1 change: 1 addition & 0 deletions js/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { default as PaymentRequest } from './PaymentRequest';
export { PKPaymentButton } from './PKPaymentButton';
export { Intents } from './Intents';
Copy link
Member

Choose a reason for hiding this comment

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

Nice, I like it. Maybe better to do an export default in Intents.js and then export { default as Intents } here. Saves you embedding everything inside a single object