I am new to iOS programming.
I am trying to integrate Stripe to my iOS app.
It gives me the following error.
First throw call stack: ( 0 CoreFoundation
0x037c1946 exceptionPreprocess + 182 1 libobjc.A.dylib
0x03075a97 objc_exception_throw + 44 2 CoreFoundation
0x037c186d +[NSException raise:format:] + 141 3 ValenX
0x00343c63 +[Stripe validateKey:] + 163 4 ValenX
0x0034539a +[Stripe createTokenWithCard:publishableKey:operationQueue:completion:] + 314 5 ValenX 0x0034612e +[Stripe createTokenWithCard:publishableKey:completion:] + 222 6 ValenX
0x00345fff +[Stripe createTokenWithCard:completion:] + 175 7 ValenX 0x000cf59f -[V_BuyStripeVC saveButtonAction:] + 879 8
libobjc.A.dylib 0x0308b7cd -[NSObject performSelector:withObject:withObject:] + 84 9 UIKit
0x01aea23d -[UIApplication sendAction:to:from:forEvent:] + 99 10 UIKit 0x01aea1cf -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64 11 UIKit
0x01c1de86 -[UIControl sendAction:to:forEvent:] + 69 12 UIKit
0x01c1e2a3 -[UIControl _sendActionsForEvents:withEvent:] + 598 13 UIKit 0x01c1d50d -[UIControl touchesEnded:withEvent:] + 660 14 UIKit
0x01b3a60a -[UIWindow _sendTouchesForEvent:] + 874 15 UIKit
0x01b3b0e5 -[UIWindow sendEvent:] + 791 16 UIKit
0x01b00549 -[UIApplication sendEvent:] + 242 17 UIKit
0x01b1037e _UIApplicationHandleEventFromQueueEvent + 20690 18 UIKit 0x01ae4b19 _UIApplicationHandleEventQueue + 2206 19 CoreFoundation
0x036e51df __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 15 20 CoreFoundation 0x036daced __CFRunLoopDoSources0 + 253 21 CoreFoundation 0x036da248 __CFRunLoopRun + 952 22 CoreFoundation
0x036d9bcb CFRunLoopRunSpecific + 443 23 CoreFoundation
0x036d99fb CFRunLoopRunInMode + 123 24 GraphicsServices
0x0510624f GSEventRunModal + 192 25 GraphicsServices
0x0510608c GSEventRun + 104 26 UIKit
0x01ae88b6 UIApplicationMain + 1526 27 ValenX
0x000cf0ce top_level_code + 78 28 ValenX
0x000cf10b main + 43 29 libdyld.dylib
0x04105ac9 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException
Below is the code.
#import <AFNetworking/AFNetworking.h>
#import "Stripe.h"
#import "V_BuyStripeVC.h"
#import "PTKView.h"
#import "STPToken.h"
#define STRIPE_TEST_PUBLIC_KEY @"pk_test_vh4FFxERgMGtcs344RkWEfpC"
#define STRIPE_TEST_POST_URL @"http://s547905537.onlinehome.us/ValenX/serverauth.json"
@interface V_BuyStripeVC ()<PTKViewDelegate>
@property(weak, nonatomic) PTKView *paymentView;
@property (strong, nonatomic) IBOutlet UIButton *saveButton;
@end
@implementation V_BuyStripeVC
- (IBAction)saveButtonAction:(UIButton *)sender {
STPCard *card = [[STPCard alloc] init];
//STPToken *token = [[STPToken alloc]init];
card.number = self.paymentView.card.number;
card.expMonth = self.paymentView.card.expMonth;
card.expYear = self.paymentView.card.expYear;
card.cvc = self.paymentView.card.cvc;
[Stripe createTokenWithCard:card completion:^(STPToken *token, NSError *error) {
if (error) {
[self handleError:error];
} else {
[self postStripeToken:token];
}
}];
}
- (void)postStripeToken:(STPToken* )token {
//1
/*
NSURL *postURL = [NSURL URLWithString:STRIPE_TEST_POST_URL];
AFHTTPClient* httpClient = [AFHTTPClient clientWithBaseURL:postURL];
httpClient.parameterEncoding = AFJSONParameterEncoding;
[httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]];
[httpClient setDefaultHeader:@"Accept" value:@"text/json"];
*/
//2
// RWCheckoutCart* checkoutCart = [RWCheckoutCart sharedInstance];
NSInteger totalCents = 20000;
//3
NSMutableDictionary* postRequestDictionary = [[NSMutableDictionary alloc] init];
postRequestDictionary[@"stripeAmount"] = [NSString stringWithFormat:@"%d", totalCents];
postRequestDictionary[@"stripeCurrency"] = @"usd";
postRequestDictionary[@"stripeToken"] = token;
postRequestDictionary[@"stripeDescription"] = @"Purchase from FoodApp iOS app!";
//4
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager POST:@"http://s547905537.onlinehome.us/ValenX/serverauth.php" parameters:postRequestDictionary success:^(AFHTTPRequestOperation *operation, id responseObject) {
[self chargeDidSucceed];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[self chargeDidNotSuceed];
}];
self.saveButton.enabled = YES;
}
- (void)viewDidLoad
{
[super viewDidLoad];
PTKView *view = [[PTKView alloc] initWithFrame:CGRectMake(15,20,290,55)];
self.paymentView = view;
self.paymentView.delegate = self;
[self.view addSubview:self.paymentView];
}
- (void)paymentView:(PTKView *)view withCard:(PTKCard *)card isValid:(BOOL)valid
{
// Toggle navigation, for example
self.saveButton.enabled = valid;
}
- (void)handleError:(NSError *) error {
//1
if ([error.domain isEqualToString:@"StripeDomain"]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
//2
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Please try again"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
self.saveButton.enabled = YES;
}
- (void)chargeDidSucceed {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Success"
message:@"Please enjoy your meal."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
//Send confirmation email
//RWEmailManager* emailManager = [[RWEmailManager alloc] initWithRecipient:self.nameTextField.text
//recipientEmail:self.emailTextField.text];
//[emailManager sendConfirmationEmail];
//RWCheckoutCart* checkoutCart = [RWCheckoutCart sharedInstance];
//[checkoutCart clearCart];
[self.navigationController popToRootViewControllerAnimated:YES];
}
- (void)chargeDidNotSuceed {
//2
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Payment not successful"
message:@"Please try again later."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
@end
I am stuck with this for last 1 week. Any help is appreciated.
Regards, Anand