Hi i am trying to integrate Paypal service but its giving error
Error :
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '- [PayPalPaymentViewController payPalServiceManager]: unrecocnized selector sent to instance 0x12784450'
Code :
- (IBAction)buttonPaypalAction:(id)sender
{
gateway = #"Paypal";
PayPalPayment *payment = [[PayPalPayment alloc] init];
payment.amount = [[NSDecimalNumber alloc] initWithString:[appDelegate.orderDetails objectAtIndex:6]];
payment.currencyCode = appDelegate.currencyCode;
payment.shortDescription = #"Food items";
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.
}
// Update payPalConfig re accepting credit cards.
// self.payPalConfig.acceptCreditCards = self.acceptCreditCards;
PayPalPaymentViewController *paymentViewController = [[PayPalPaymentViewController alloc] initWithPayment:payment configuration:self.payPalConfig delegate:self];
// error is coming after this line...
[self presentViewController:paymentViewController animated:YES completion:nil];
}
Don't forgot to add -lc++ -ObjC in Other linker flags
Related
I am using Paypal SandBox Environment. When I am opening Paypal from device i am getting this error:
Request has failed with error: pp_service_error_json_parse_error - System error. Please try again later. (403) | Details: (
{
"ns_error" = "Error Domain=NSCocoaErrorDomain Code=3840 \"JSON text did not start with array or object and option to allow fragments not set.\" UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}";
}
).
check Screenshot
Here is My code
_payPalConfig = [[PayPalConfiguration alloc] init];
_payPalConfig.acceptCreditCards = YES;
#else
_payPalConfig.acceptCreditCards = NO;
#endif
_payPalConfig.merchantName = #"";
_payPalConfig.merchantPrivacyPolicyURL = [NSURL URLWithString:#""];
_payPalConfig.merchantUserAgreementURL = [NSURL URLWithString:#""];
_payPalConfig.languageOrLocale = [NSLocale preferredLanguages][0];
_payPalConfig.payPalShippingAddressOption = PayPalShippingAddressOptionPayPal;
self.environment = PayPalEnvironmentSandbox;
nslog(#"PayPal iOS SDK version: %#", [PayPalMobile libraryVersion]);
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:YES];
// Preconnect to PayPal early
[self setPayPalEnvironment:self.environment];
}
- (void)setPayPalEnvironment:(NSString *)environment
{
self.environment = environment;
[PayPalMobile initializeWithClientIdsForEnvironments:#{PayPalEnvironmentSandbox:PAYPAL_CLIENT_KEY}];
[PayPalMobile preconnectWithEnvironment:environment];
}
I am not getting why i am getting error.
Anyone is having solution?
Background: I used same code for iOS 8.2,8.3 it was working fine.
PKPaymentAuthorizationViewController *paymentPane = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:request];
paymentPane.delegate = self;
[self presentViewController:paymentPane animated:TRUE completion:nil];
PaymentRequest Code:
PKPaymentRequest *request = [[PKPaymentRequest alloc] init];
NSString *chargeApplePay=[NSString stringWithFormat:#"%.02f",pay];
PKPaymentSummaryItem *total = [PKPaymentSummaryItem summaryItemWithLabel:#"Grand Total"
amount:[NSDecimalNumber decimalNumberWithString:chargeApplePay]];
request.paymentSummaryItems = #[total];
request.countryCode = #"US";
request.currencyCode = #"USD";
request.supportedNetworks = #[PKPaymentNetworkAmex, PKPaymentNetworkMasterCard, PKPaymentNetworkVisa];
request.merchantIdentifier = #"valid.com.myIdentifier";
request.merchantCapabilities = PKMerchantCapability3DS;
Question: Now on iOS 8.4 when I try to present my paymentPane its value is nil somehow.
Fatal Exception: NSInvalidArgumentException Application tried to
present a nil modal view controller on target .
What I have already tried by googling and using answers from stackoverflow.
Used Checks like
[PKPaymentAuthorizationViewController canMakePaymentsUsingNetworks:#[PKPaymentNetworkAmex, PKPaymentNetworkMasterCard, PKPaymentNetworkVisa]]
and
[PKPaymentAuthorizationViewController canMakePayments]
Checking my merchant id is valid or not.
Checking All the code I used for request is valid or not.
Check whether you've added Credit card information in your device Passbook or not.
Check whether you can make payment using your device.
Objective C :
if ([PKPaymentAuthorizationViewController canMakePayments]) {
NSLog(#"Can Make Payments");
}
else {
NSLog(#"Can't Make payments");
}
Swift :
if PKPaymentAuthorizationViewController.canMakePayments() {
NSLog(#"Can Make Payments");
}
else {
NSLog(#"Can't Make Payments");
}
Check whether you can make payment using the allowed payment networks.
Objective C :
NSArray *paymentNetworks = [NSArray arrayWithObjects:PKPaymentNetworkMasterCard, PKPaymentNetworkVisa, PKPaymentNetworkAmex, nil];
if ([PKPaymentAuthorizationViewController canMakePaymentsUsingNetworks:paymentNetworks]) {
NSLog(#"Can Make payment with your card");
}
else {
NSLog(#"Card is not supporting");
}
Swift :
let paymentNetworks = [PKPaymentNetworkAmex, PKPaymentNetworkMasterCard, PKPaymentNetworkVisa]
if PKPaymentAuthorizationViewController.canMakePaymentsUsingNetworks(paymentNetworks) {
NSLog(#"Can Make payment with your card");
}
else {
NSLog(#"Card is not supporting");
}
I have also had similar problems when running inside the Xcode debugger. As a workaround I stop the app in Xcode and then manually start the app on the iPhone or iPad.
One drawback with this is obviously that you can't debug any issues. I've had to resort to NSLog and reading the console log.
i have some problems with PayPal sdk on iOS.I created my app at https://developer.paypal.com/webapps/developer/applications/myapps and got client id . i used paypal sample apps with my ID its working fine in mock and sandbox mode. when i am using this in my apps each time my apps moving in mock data mode i am getting response from paypal server.
{
client = {
environment = mock;
"paypal_sdk_version" = "2.2.1";
platform = iOS;
"product_name" = "PayPal iOS SDK";
};
response = {
"create_time" = "2014-08-27T10:18:57Z";
id = "PAY-8UD377151U972354RKOQ3DTQ";
intent = sale;
state = approved;
};
"response_type" = payment;
}
.i am not anle to set sandbox mode which variable i need to use .
- (void)viewDidLoad
{
// Set up payPalConfig
_payPalConfig = [[PayPalConfiguration alloc] init];
_payPalConfig.acceptCreditCards = YES;
_payPalConfig.languageOrLocale = #"en";
_payPalConfig.merchantName = #"KicksCloset Shoes, Inc.";
_payPalConfig.merchantPrivacyPolicyURL = [NSURL URLWithString:#"https://www.paypal.com/webapps/mpp/ua/privacy-full"];
_payPalConfig.merchantUserAgreementURL = [NSURL URLWithString:#"https://www.paypal.com/webapps/mpp/ua/useragreement-full"];
_payPalConfig.languageOrLocale = [NSLocale preferredLanguages][0];
// use default environment, should be Production in real life
self.environment = #"sandbox";
NSLog(#"PayPal iOS SDK version: %#", [PayPalMobile libraryVersion]);
}
this is my pay action
{
PayPalPayment *payment = [[PayPalPayment alloc] init];
payment.amount = [[NSDecimalNumber alloc] initWithString:amountforserver];
payment.currencyCode = #"USD";
payment.shortDescription = creditsforserver;
// payment.items = items; // if not including multiple items, then leave payment.items as nil
// payment.paymentDetails = paymentDetails; // if not including payment details, then leave payment.paymentDetails as nil
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.
}
// Update payPalConfig re accepting credit cards.
self.payPalConfig.acceptCreditCards = self.acceptCreditCards;
PayPalPaymentViewController *paymentViewController = [[PayPalPaymentViewController alloc] initWithPayment:payment
configuration:self.payPalConfig
delegate:self];
[self presentViewController:paymentViewController animated:YES completion:nil];
}
your action method have issue .
just pass the environment
{
PayPalPayment *payment = [[PayPalPayment alloc] init];
payment.amount = [[NSDecimalNumber alloc] initWithString:amountforserver];
payment.currencyCode = #"USD";
payment.shortDescription = creditsforserver;
// payment.items = items; // if not including multiple items, then leave payment.items as nil
// payment.paymentDetails = paymentDetails; // if not including payment details, then leave payment.paymentDetails as nil
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.
}
self.environment = kPayPalEnvironment;
PayPalPaymentViewController *paymentViewController = [[PayPalPaymentViewController alloc] initWithPayment:payment
configuration:self.payPalConfig
delegate:self];
[self presentViewController:paymentViewController animated:YES completion:nil];
}
and just use this
code in
-(void)viewWillAppear:(BOOL)animated{
[PayPalMobile preconnectWithEnvironment:self.environment];
}
change your paypal environment to PayPalEnvironmentSandbox
this is for sandbox mode
self.environment = PayPalEnvironmentSandbox;
if you want go with live mode..
self.environment = PayPalEnvironmentProduction;
check your PayPalMobile.h file
/// This environment MUST be used for App Store submissions.
extern NSString *const PayPalEnvironmentProduction;
/// Sandbox: Uses the PayPal sandbox for transactions. Useful for development.
extern NSString *const PayPalEnvironmentSandbox;
/// NoNetwork: Mock mode. Does not submit transactions to PayPal. Fakes successful responses. Useful for unit tests.
extern NSString *const PayPalEnvironmentNoNetwork;
Update: hideCreditCardButton has no role in this issue, it was just a coincident that when I tried it w/o credit card it worked for me but thats not the case anymore.I does work but only 20-30% of the time.
I am using PayPal iOS SDK 1.4.6. if I use paymentViewController.hideCreditCardButton = YES; it works fine but if I set this to paymentViewController.hideCreditCardButton = NO; I get the server error (ref. to image).
here's my code:
- (void)paypalPayment {
// Create a PayPalPayment
float paypalPrice =[youPay floatValue];
NSString* currencyCode = appDelegate.countryCurrency;
if ([currencyCode isEqual: #"INR"]) {
float new = [[[ExchangeRate sharedManager]getExchangeRate:#"INR" toCurrency:#"USD"]
floatValue];
paypalPrice = paypalPrice*new;
}
PayPalPayment *payment = [[PayPalPayment alloc] init];
payment.amount = [[NSDecimalNumber alloc] initWithString:
[NSString stringWithFormat:#"%.2f",paypalPrice]];
payment.currencyCode = #"USD";
payment.shortDescription = #"Total Order";
[PayPalPaymentViewController setEnvironment:PayPalEnvironmentProduction];
// Provide a payerId that uniquely identifies a user within the scope of your system,
// such as an email address or user ID.
NSString *aPayerId = #"abc#msronline.in";
PayPalPaymentViewController *paymentViewController;
paymentViewController = [[PayPalPaymentViewController alloc]
initWithClientId:kPayPalClientId
receiverEmail:kPayPalReceiverEmail
payerId:aPayerId
payment:payment
delegate:self];
paymentViewController.languageOrLocale = #"en";
paymentViewController.hideCreditCardButton = NO;
[self presentViewController:paymentViewController animated:YES completion:nil];
}
Dave from PayPal here.
That's indeed weird. You're getting this as soon as you present the viewcontroller? Is it still happening today?
From your screenshot, it looks like the SDK is still trying to get an initial connection with the PayPal server. At this early stage, the setting of hideCreditCardButton shouldn't yet affect anything.
You are using the Client ID that's designated for Production (as opposed to the Client ID designated for Sandbox), right?
Do you see anything helpful in the console log?
I have same issue and solved by change kPayPalReceiverEmail.
If you use same email as kPayPalReceiverEmail to login in paypal to send payment than this error comes.
I just change kPayPalReceiverEmail email to another one and I get successful response from paypal server.
It may help you
I am trying to implement the Paypal SDK into my iOS app. I copied the code exactly from the Readme instructions, imported the files, and linked my button to my action but when I clicked the button it gives me a "Thread 1 signal:SIGABRT" error and crashes.
Here is the Paypal code in my .m files:
- (IBAction)pay {
// Create a PayPalPayment
PayPalPayment *payment = [[PayPalPayment alloc] init];
payment.amount = [[NSDecimalNumber alloc] initWithString:#"39.95"];
payment.currencyCode = #"USD";
payment.shortDescription = #"Product";
// Check whether payment is processable.
if (!payment.processable) {
// If, for example, the amount was negative or the shortDescription was empty, then
// this payment would not be processable. You would want to handle that here.
}
// Provide a payerId that uniquely identifies a user within the scope of your system,
// such as an email address or user ID.
NSString *aPayerId = #"someone#someone.com";
// Create a PayPalPaymentViewController with the credentials and payerId, the PayPalPayment
// from the previous step, and a PayPalPaymentDelegate to handle the results.
PayPalPaymentViewController *paymentViewController;
paymentViewController = [[PayPalPaymentViewController alloc] initWithClientId:#"MY-CLIENT-ID-HERE"
receiverEmail:#"MY-EMAIL-HERE"
payerId:aPayerId
payment:payment
delegate:self];
// Present the PayPalPaymentViewController.
[self presentViewController:paymentViewController animated:YES completion:nil];
}
#pragma mark - PayPalPaymentDelegate methods
- (void)payPalPaymentDidComplete:(PayPalPayment *)completedPayment {
// Payment was processed successfully; send to server for verification and fulfillment.
[self verifyCompletedPayment:completedPayment];
// Dismiss the PayPalPaymentViewController.
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)payPalPaymentDidCancel {
// The payment was canceled; dismiss the PayPalPaymentViewController.
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)verifyCompletedPayment:(PayPalPayment *)completedPayment {
// Send the entire confirmation dictionary
NSData *confirmation = [NSJSONSerialization dataWithJSONObject:completedPayment.confirmation
options:0
error:nil];
// Send confirmation to your server; your server should verify the proof of payment
// and give the user their goods or services. If the server is not reachable, save
// the confirmation and try again later.
}
Does anyone have any ideas what the problem might be?
You know what?
cuz you use decimal number on you currency.
so you need do something in this code
// Check whether payment is processable.
if (!payment.processable) {
// If, for example, the amount was negative or the shortDescription was empty, then
// this payment would not be processable. You would want to handle that here.
}
If you in debug point you can find a keyword in payment, display, it's mean your currency will change to 40.0.
Try it.