我是iOS编程的新手。Stripe与iOS和PHP的集成
我正在尝试将Stripe整合到我的iOS app
。
它给我以下错误。
第一掷调用堆栈:(0的CoreFoundation
0x037c1946 exceptionPreprocess + 182 1 libobjc.A.dylib
0x03075a97 objc_exception_throw + 44 2的CoreFoundation
0x037c186d + [NSException提高:格式:] + 141 3 ValenX
0x00343c63 + [条纹validateKey:] + 163 4 ValenX
0x0034539a + [条纹 createTokenWithCard:publishableKey:operationQueue:完成:] + 314 5 ValenX 0x0034612e + [条纹 CRE ateTokenWithCard:publishableKey:完成:] + 222 6 ValenX
0x00345fff + [条纹createTokenWithCard:完成:] + 175 7 ValenX 0x000cf59f - [V_BuyStripeVC saveButtonAction:] + 879 8
libobjc.A.dylib 0x0308b7cd - [NSObject的 performSelector :withObject:withObject:] + 84 9的UIKit
0x01aea23d - [UIApplication的sendAction:为:从: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 1 3 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 0x036d A248 __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:终止未捕获 异常类型NSException
以下是代码。
#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
我坚持这个去年1周。任何帮助表示赞赏。
问候, 阿南德
你可以请你的项目添加到github并发布链接。 – rshankar 2014-11-09 04:17:16
我建议你重新格式化你可怕的格式错误信息。将它放在代码块中应该使其可读。 – 2015-10-19 23:59:44