bnjmn.myers
bnjmn.myers

Reputation: 439

PayPal API error

I'm trying to integrate the PayPal API into my iPhone app but when I segue to the controller that handles it I get the following error:

-[UIDevice platformType]: unrecognized selector sent to instance 0xc25ff20 2014-01-23 15:26:57.668 FuzionStudio[27749:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIDevice platformType]: unrecognized selector sent to instance 0xc25ff20'

Has anyone else run into this issue?

#import "ZZMainViewController.h"
#import <QuartzCore/QuartzCore.h>

#warning "Enter your credentials"
#define kPayPalClientId @"YOUR CLIENT ID HERE"
#define kPayPalReceiverEmail @"[email protected]"

@interface ZZMainViewController ()

@property(nonatomic, strong, readwrite) IBOutlet UIButton *payButton;
@property(nonatomic, strong, readwrite) IBOutlet UIView *successView;

@end

@implementation ZZMainViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  self.title = @"Tuition Payment";
  self.acceptCreditCards = YES;
  self.environment = PayPalEnvironmentNoNetwork;
  // Do any additional setup after loading the view, typically from a nib.

  self.successView.hidden = YES;

  NSLog(@"PayPal iOS SDK version: %@", [PayPalPaymentViewController libraryVersion]);
}

- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:YES];

  UIEdgeInsets insets = UIEdgeInsetsMake(0, 15.0f, 0, 14.0f);
  UIImage *payBackgroundImage = [[UIImage imageNamed:@"button_secondary.png"] resizableImageWithCapInsets:insets];
  UIImage *payBackgroundImageHighlighted = [[UIImage imageNamed:@"button_secondary_selected.png"] resizableImageWithCapInsets:insets];
  [self.payButton setBackgroundImage:payBackgroundImage forState:UIControlStateNormal];
  [self.payButton setBackgroundImage:payBackgroundImageHighlighted forState:UIControlStateHighlighted];
  [self.payButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
  [self.payButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateHighlighted];

  // Optimization: Prepare for display of the payment UI by getting network work done early
  [PayPalPaymentViewController setEnvironment:self.environment];
  [PayPalPaymentViewController prepareForPaymentUsingClientId:kPayPalClientId];
}

- (void)didReceiveMemoryWarning {
  [super didReceiveMemoryWarning];
  // Dispose of any resources that can be recreated.
}

pragma mark - Pay action

- (IBAction)pay {

  // Remove our last completed payment, just for demo purposes.
  self.completedPayment = nil;

  PayPalPayment *payment = [[PayPalPayment alloc] init];
  payment.amount = [[NSDecimalNumber alloc] initWithString:@"9.95"];
  payment.currencyCode = @"USD";
  payment.shortDescription = @"Hipster t-shirt";

  if (!payment.processable) {
    // This particular payment will always be processable. If, for
    // example, the amount was negative or the shortDescription was
    // empty, this payment wouldn't be processable, and you'd want
    // to handle that here.
  }

  // Any customer identifier that you have will work here. Do NOT use a device- or
  // hardware-based identifier.
  NSString *customerId = @"user-11723";

  // Set the environment:
  // - For live charges, use PayPalEnvironmentProduction (default).
  // - To use the PayPal sandbox, use PayPalEnvironmentSandbox.
  // - For testing, use PayPalEnvironmentNoNetwork.
  [PayPalPaymentViewController setEnvironment:self.environment];

  PayPalPaymentViewController *paymentViewController = [[PayPalPaymentViewController alloc] initWithClientId:kPayPalClientId
                                                                                               receiverEmail:kPayPalReceiverEmail
                                                                                                     payerId:customerId
                                                                                                     payment:payment
                                                                                                    delegate:self];
  paymentViewController.hideCreditCardButton = !self.acceptCreditCards;

  // Setting the languageOrLocale property is optional.
  //
  // If you do not set languageOrLocale, then the PayPalPaymentViewController will present
  // its user interface according to the device's current language setting.
  //
  // Setting languageOrLocale to a particular language (e.g., @"es" for Spanish) or
  // locale (e.g., @"es_MX" for Mexican Spanish) forces the PayPalPaymentViewController
  // to use that language/locale.
  //
  // For full details, including a list of available languages and locales, see PayPalPaymentViewController.h.
  paymentViewController.languageOrLocale = @"en";

  [self presentViewController:paymentViewController animated:YES completion:nil];
}

pragma mark - Proof of payment validation

- (void)sendCompletedPaymentToServer:(PayPalPayment *)completedPayment {
  // TODO: Send completedPayment.confirmation to server
  NSLog(@"Here is your proof of payment:\n\n%@\n\nSend this to your server for confirmation and fulfillment.", completedPayment.confirmation);
}

pragma mark - PayPalPaymentDelegate methods

- (void)payPalPaymentDidComplete:(PayPalPayment *)completedPayment {
  NSLog(@"PayPal Payment Success!");
  self.completedPayment = completedPayment;
  self.successView.hidden = NO;

  [self sendCompletedPaymentToServer:completedPayment]; // Payment was processed successfully; send to server for verification and fulfillment
  [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)payPalPaymentDidCancel {
  NSLog(@"PayPal Payment Canceled");
  self.completedPayment = nil;
  self.successView.hidden = YES;
  [self dismissViewControllerAnimated:YES completion:nil];
}

Upvotes: 1

Views: 734

Answers (1)

Dave Goldman
Dave Goldman

Reputation: 2257

Dave from PayPal here.

@bnjmn.myers, did you notice this bit in the integration instructions?

In your project's Build Settings (in the TARGETS section, not the PROJECTS section) add -lc++ -ObjC to Other Linker Flags.

If you hadn't caught that previously, does following that advice now fix your problem?

Upvotes: 1

Related Questions