Created
February 1, 2015 21:01
-
-
Save vikdenic/1f9c4089d710ae7a2c6e to your computer and use it in GitHub Desktop.
may cloud call from code stripe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| NSDictionary *chargeParams = @{ | |
| @"token": token.tokenId, | |
| @"currency": @"usd", | |
| @"amount": result, // this is in cents (i.e. 1000 = $10) | |
| @"lineItems": self.lineItems, | |
| @"name": self.shippingName, | |
| @"email": self.email, | |
| @"address": self.shippingAddress, | |
| @"cityState": self.cityState, | |
| @"zipcode": self.zipcode, | |
| }; | |
| if (!ParseApplicationId || !ParseClientKey) { | |
| UIAlertView *message = | |
| [[UIAlertView alloc] initWithTitle:@"Todo: Submit this token to your backend" | |
| message:[NSString stringWithFormat:@"Good news! Stripe turned your credit card into a token: %@ \nYou can follow the " | |
| @"instructions in the README to set up Parse as an example backend, or use this " | |
| @"token to manually create charges at dashboard.stripe.com .", | |
| token.tokenId] | |
| delegate:nil | |
| cancelButtonTitle:NSLocalizedString(@"OK", @"OK") | |
| otherButtonTitles:nil]; | |
| [message show]; | |
| [MBProgressHUD hideHUDForView:self.view animated:YES]; | |
| [self.presentingViewController dismissViewControllerAnimated:YES completion:nil]; | |
| return; | |
| } | |
| // This passes the token off to our payment backend, which will then actually complete charging the card using your account's | |
| [PFCloud callFunctionInBackground:@"charge" | |
| withParameters:chargeParams | |
| block:^(id object, NSError *error) { | |
| [MBProgressHUD hideHUDForView:self.view animated:YES]; | |
| if (error) { | |
| [self hasError:error]; | |
| return; | |
| } | |
| else | |
| { | |
| NSString *storyboardName = @"Main"; | |
| UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil]; | |
| UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"id"]; | |
| [self presentViewController:vc animated:YES completion:^{ | |
| [[[UIAlertView alloc] initWithTitle:@"Payment Succeeded!" | |
| message:[NSString stringWithFormat:@"An email confirmation was sent to %@", self.email] | |
| delegate:nil | |
| cancelButtonTitle:nil | |
| otherButtonTitles:@"OK", nil] show]; | |
| }]; | |
| [self clearShoppingCart]; | |
| } | |
| }]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment