1111
1212@interface ExampleWindowController () <STPCheckoutViewControllerDelegate>
1313@property STPCheckoutViewController *checkoutController;
14+ @property (weak ) IBOutlet NSButton *buyButton;
1415@end
1516
1617@implementation ExampleWindowController
1718
1819- (IBAction )beginPayment : (id )sender {
1920 STPCheckoutOptions *options = [STPCheckoutOptions new ];
20- options.publishableKey = @" pk_test_09IUAkhSGIz8mQP3prdgKm06 " ;
21+ options.publishableKey = [Stripe defaultPublishableKey ] ;
2122 options.appleMerchantId = @" <#Replace me with your Apple Merchant ID #>" ;
2223 options.purchaseDescription = @" Tasty Llama food" ;
2324 options.purchaseAmount = @1000 ;
@@ -38,26 +39,27 @@ - (IBAction)beginPayment:(id)sender {
3839 options: NSLayoutFormatDirectionLeadingToTrailing
3940 metrics: nil
4041 views: NSDictionaryOfVariableBindings(webView)]];
41- [ self .window.contentViewController addChildViewController: self .checkoutController] ;
42+ self.buyButton . enabled = NO ;
4243}
4344
4445- (void )checkoutController : (STPCheckoutViewController *)controller didCreateToken : (STPToken *)token completion : (STPTokenSubmissionHandler)completion {
46+ self.buyButton .enabled = YES ;
4547 completion (STPBackendChargeResultSuccess, nil );
4648}
4749
4850- (void )checkoutController : (STPCheckoutViewController *)controller didFailWithError : (NSError *)error {
51+ self.buyButton .enabled = YES ;
4952 [controller.view removeFromSuperview ];
50- [controller removeFromParentViewController ];
5153}
5254
5355- (void )checkoutControllerDidCancel : (STPCheckoutViewController *)controller {
56+ self.buyButton .enabled = YES ;
5457 [controller.view removeFromSuperview ];
55- [controller removeFromParentViewController ];
5658}
5759
5860- (void )checkoutControllerDidFinish : (STPCheckoutViewController *)controller {
61+ self.buyButton .enabled = YES ;
5962 [controller.view removeFromSuperview ];
60- [controller removeFromParentViewController ];
6163}
6264
6365@end
0 commit comments