forked from datapimp/react-native-apple-pay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStripeManager.m
52 lines (42 loc) · 1.65 KB
/
StripeManager.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#import "StripeManager.h"
#import "ApplePayManager.h"
@implementation StripeManager
+ (void)handlePaymentAuthorizationWithPayment:(NSString *)publishableKey
payment:(PKPayment *)payment
completion:(void (^)(PKPaymentAuthorizationStatus))completion
callback:(RCTResponseSenderBlock)callback
{
// Set Stripe Pubishable Key
[Stripe setDefaultPublishableKey:publishableKey];
// Create Token
// [[STPAPIClient sharedClient] createTokenWithPayment:payment completion:^(STPToken *token, NSError *error)
// {
// // Error creating token with Stripe
// if (error) {
// NSLog(@"error: %@", error);
// completion(PKPaymentAuthorizationStatusFailure);
// return;
// }
// [self createBackendChargeWithToken:token completion:completion];
//
// }];
// Creating Tokens with ApplePay Test Cards currently fails. So for now we'll just create tokens with a Stripe Test Card.
STPCard *card = [[STPCard alloc] init];
card.number = @"4242 4242 4242 4242";
card.expMonth = 11;
card.expYear = 19;
card.cvc = @"310";
[[STPAPIClient sharedClient] createTokenWithCard:card completion:^(STPToken *token, NSError *error)
{
if (error) {
NSLog(@"Stripe Error: %@", error);
completion(PKPaymentAuthorizationStatusFailure);
return;
} else {
NSLog(@"Stripe Token: %@", token.tokenId);
// Send token to JS
callback(@[[NSNull null], token.tokenId]);
}
}];
}
@end