Setup Paypal client ID for credentials IOS SDK 2.1.6 - ios

Im using Paypal SDK in my app. I set my environment into PayPalEnvironmentSandbox but when I run my app theres an alert saying "There was a problem communicating with the Paypal servers. Please Try again". I googled a lot of times, other said that I need to change the clientId but i dont know how to change the client Id, I have a test account on sandbox in paypal but i dont know how to implement them in my app. I read the documentation and they said that I need to change may Client Id something like that but i dont know how. Need your help guys thank you. I am using iOS paypal SDK 2.1.6.
Code:
#import "ZZMainViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "PayPalMobile.h"
// Set the environment:
// - For live charges, use PayPalEnvironmentProduction (default).
// - To use the PayPal sandbox, use PayPalEnvironmentSandbox.
// - For testing, use PayPalEnvironmentNoNetwork.
//#define kPayPalEnvironment PayPalEnvironmentNoNetwork
#define kPayPalEnvironment PayPalEnvironmentSandbox
#interface ZZMainViewController ()
#property(nonatomic, strong, readwrite) IBOutlet UIButton *payNowButton;
#property(nonatomic, strong, readwrite) IBOutlet UIButton *payFutureButton;
#property(nonatomic, strong, readwrite) IBOutlet UIView *successView;
#property(nonatomic, strong, readwrite) PayPalConfiguration *payPalConfig;
#end
#implementation ZZMainViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
// Set up payPalConfig
_payPalConfig = [[PayPalConfiguration alloc] init];
_payPalConfig.acceptCreditCards = YES;
_payPalConfig.languageOrLocale = #"en";
_payPalConfig.merchantName = #"Awesome Shirts, 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"];
// 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.
_payPalConfig.languageOrLocale = [NSLocale preferredLanguages][0];
// Do any additional setup after loading the view, typically from a nib.
self.successView.hidden = YES;
// use default environment, should be Production in real life
//self.environment = kPayPalEnvironment;
//self.environment = PayPalEnvironmentSandbox;
[PayPalMobile preconnectWithEnvironment:PayPalEnvironmentSandbox];
NSLog(#"PayPal iOS SDK version: %#", [PayPalMobile libraryVersion]);
[self pay];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:YES];
// Preconnect to PayPal early
[PayPalMobile preconnectWithEnvironment:PayPalEnvironmentSandbox];
}
#pragma mark - Receive Single Payment
- (void)pay {
// Remove our last completed payment, just for demo purposes.
self.resultText = nil;
// Note: For purposes of illustration, this example shows a payment that includes
// both payment details (subtotal, shipping, tax) and multiple items.
// You would only specify these if appropriate to your situation.
// Otherwise, you can leave payment.items and/or payment.paymentDetails nil,
// and simply set payment.amount to your total charge.
// Optional: include multiple items
PayPalItem *item1 = [PayPalItem itemWithName:#"Old jeans with holes"
withQuantity:2
withPrice:[NSDecimalNumber decimalNumberWithString:#"84.99"]
withCurrency:#"USD"
withSku:#"Hip-00037"];
PayPalItem *item2 = [PayPalItem itemWithName:#"Free rainbow patch"
withQuantity:1
withPrice:[NSDecimalNumber decimalNumberWithString:#"0.00"]
withCurrency:#"USD"
withSku:#"Hip-00066"];
PayPalItem *item3 = [PayPalItem itemWithName:#"Long-sleeve plaid shirt (mustache not included)"
withQuantity:1
withPrice:[NSDecimalNumber decimalNumberWithString:#"37.99"]
withCurrency:#"USD"
withSku:#"Hip-00291"];
NSArray *items = #[item1, item2, item3];
NSDecimalNumber *subtotal = [PayPalItem totalPriceForItems:items];
// Optional: include payment details
NSDecimalNumber *shipping = [[NSDecimalNumber alloc] initWithString:#"5.99"];
NSDecimalNumber *tax = [[NSDecimalNumber alloc] initWithString:#"2.50"];
PayPalPaymentDetails *paymentDetails = [PayPalPaymentDetails paymentDetailsWithSubtotal:subtotal
withShipping:shipping
withTax:tax];
NSDecimalNumber *total = [[subtotal decimalNumberByAdding:shipping] decimalNumberByAdding:tax];
PayPalPayment *payment = [[PayPalPayment alloc] init];
payment.amount = total;
payment.currencyCode = #"USD";
payment.shortDescription = #"Hipster clothing";
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];
}
#pragma mark PayPalPaymentDelegate methods
- (void)payPalPaymentViewController:(PayPalPaymentViewController *)paymentViewController didCompletePayment:(PayPalPayment *)completedPayment {
NSLog(#"PayPal Payment Success!");
self.resultText = [completedPayment description];
[self showSuccess];
[self sendCompletedPaymentToServer:completedPayment]; // Payment was processed successfully; send to server for verification and fulfillment
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)payPalPaymentDidCancel:(PayPalPaymentViewController *)paymentViewController {
NSLog(#"PayPal Payment Canceled");
self.resultText = nil;
self.successView.hidden = YES;
[self dismissViewControllerAnimated: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 - Authorize Future Payments
- (IBAction)getUserAuthorization:(id)sender {
PayPalFuturePaymentViewController *futurePaymentViewController = [[PayPalFuturePaymentViewController alloc] initWithConfiguration:self.payPalConfig delegate:self];
[self presentViewController:futurePaymentViewController animated:YES completion:nil];
}
#pragma mark PayPalFuturePaymentDelegate methods
- (void)payPalFuturePaymentViewController:(PayPalFuturePaymentViewController *)futurePaymentViewController didAuthorizeFuturePayment:(NSDictionary *)futurePaymentAuthorization {
NSLog(#"PayPal Future Payment Authorization Success!");
self.resultText = futurePaymentAuthorization[#"code"];
[self showSuccess];
[self sendAuthorizationToServer:futurePaymentAuthorization];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)payPalFuturePaymentDidCancel:(PayPalFuturePaymentViewController *)futurePaymentViewController {
NSLog(#"PayPal Future Payment Authorization Canceled");
self.successView.hidden = YES;
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)sendAuthorizationToServer:(NSDictionary *)authorization {
// TODO: Send authorization to server
NSLog(#"Here is your authorization:\n\n%#\n\nSend this to your server to complete future payment setup.", authorization);
}
#pragma mark - Helpers
- (void)showSuccess {
self.successView.hidden = NO;
self.successView.alpha = 1.0f;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:2.0];
self.successView.alpha = 0.0f;
[UIView commitAnimations];
}
#pragma mark - Flipside View Controller
- (void)flipsideViewControllerDidFinish:(ZZFlipsideViewController *)controller {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
[self dismissViewControllerAnimated:YES completion:nil];
} else {
[self.flipsidePopoverController dismissPopoverAnimated:YES];
self.flipsidePopoverController = nil;
}
}
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
self.flipsidePopoverController = nil;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"pushSettings"]) {
[[segue destinationViewController] setDelegate:self];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
UIPopoverController *popoverController = [(UIStoryboardPopoverSegue *)segue popoverController];
self.flipsidePopoverController = popoverController;
popoverController.delegate = self;
}
}
}
- (IBAction)togglePopover:(id)sender {
if (self.flipsidePopoverController) {
[self.flipsidePopoverController dismissPopoverAnimated:YES];
self.flipsidePopoverController = nil;
} else {
[self performSegueWithIdentifier:#"showAlternate" sender:sender];
}
}
#end

Dave from PayPal here.
To set your client IDs (one for Sandbox, one for Live), see step 1 in our Sample Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// ...
[PayPalMobile initializeWithClientIdsForEnvironments:#{PayPalEnvironmentProduction : #"YOUR_CLIENT_ID_FOR_PRODUCTION",
PayPalEnvironmentSandbox : #"YOUR_CLIENT_ID_FOR_SANDBOX"}];
// ...
return YES;
}

For Swift development
[PayPalMobile initializeWithClientIdsForEnvironments:#{PayPalEnvironmentProduction :#"YOUR_CLIENT_ID_FOR_PRODUCTION",
PayPalEnvironmentSandbox : #"ATIXyxAAjtL8-HdqfLq0kTCeefUi1SNI_xkfWktHelloqznRxsrm_Hello"}];
Will not work you need to do instead
PayPalMobile.initializeWithClientIdsForEnvironments([PayPalEnvironmentProduction: "ID1", PayPalEnvironmentSandbox: "ID2"])

To get a client_id you need to register & create an app at https://developer.paypal.com/webapps/developer/applications/myapps. You will then get sandbox (and live) credentials.

you have to change inside appdelegate.m file.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { #warning "Enter your credentials"
[PayPalMobile initializeWithClientIdsForEnvironments:#{PayPalEnvironmentProduction : #"YOUR_CLIENT_ID_FOR_PRODUCTION",
PayPalEnvironmentSandbox : #"ATIXyxAAjtL8-HdqfLq0kTCeefUi1SNI_xkfWktHelloqznRxsrm_Hello"}]; return YES;}

Related

PayPal payment stuck "processing"

I've implemented the latest PayPal API but every time I try to run the payment through PayPal's sandbox the payment just gets stuck on "Processing." Totally stumped. Thanks!
-(void)payWithPayPal {
NSString *shortDescription = [NSString stringWithFormat:#"%i %#", [Global sharedInstance].currentOrder.itemQuantity, [Global sharedInstance].currentOrder.boozeBrand];
NSDecimalNumber *paymentDecimal = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:#"%.02f", [Global sharedInstance].currentOrder.itemPrice]];
NSString *sku = [NSString stringWithFormat:#"DBAR-%i", [Global sharedInstance].currentOrder.orderNumber];
NSString *name = [NSString stringWithFormat:#"%#", [Global sharedInstance].currentOrder.boozeBrand];
PayPalItem *item = [PayPalItem itemWithName:name
withQuantity:[Global sharedInstance].currentOrder.itemQuantity
withPrice:paymentDecimal
withCurrency:#"USD"
withSku:sku];
float priceFloat = [item.price floatValue];
float totalFloat = priceFloat * item.quantity;
NSDecimalNumber *total = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:#"%.02f", totalFloat]];
PayPalPayment *payment = [[PayPalPayment alloc] init];
payment.amount = total;
payment.currencyCode = #"USD";
payment.shortDescription = shortDescription;
payment.items = nil; // if not including multiple items, then leave payment.items as nil
payment.paymentDetails = nil; // if not including payment details, then leave payment.paymentDetails as nil
if (!payment.processable) {NSLog(#"Payment not processable.");}
// Update payPalConfig re accepting credit cards.
PayPalPaymentViewController *paymentViewController = [[PayPalPaymentViewController alloc] initWithPayment:payment configuration:self.payPalConfiguration delegate:self];
[self presentViewController:paymentViewController animated:YES completion:nil];
}
#pragma mark - PayPalDelegate
-(void)payPalPaymentViewController:(PayPalPaymentViewController *)paymentViewController willCompletePayment:(PayPalPayment *)completedPayment completionBlock:(PayPalPaymentDelegateCompletionBlock)completionBlock {
NSLog(#"Payment processing.");
//Stuck on this forever - this is what I'm trying to get past
}
-(void)payPalPaymentViewController:(PayPalPaymentViewController *)paymentViewController didCompletePayment:(PayPalPayment *)completedPayment {
//Never gets here
}
You issue is in the completion block of willCompletePayment, you need to return the completion block after you have complete the processing in that
to call the didCompletePayment
From Paypal code documentation
Your code MUST finish by calling the completionBlock.
completionBlock Block to execute when your processing is done.
so your code will be like
- (void)payPalPaymentViewController:(nonnull PayPalPaymentViewController *)paymentViewController
willCompletePayment:(nonnull PayPalPayment *)completedPayment
completionBlock:(nonnull PayPalPaymentDelegateCompletionBlock)completionBlock {
//do all the code you want
completionBlock();
}
After you write this completion block it will go to didCompletePayment, which can be like this:
- (void)payPalPaymentViewController:(PayPalPaymentViewController *)paymentViewController didCompletePayment:(PayPalPayment *)completedPayment {
NSLog(#"PayPal Payment Success!");
self.resultText = [completedPayment description];
[self showSuccess];
[self dismissViewControllerAnimated:YES completion:nil];
}
Another Option
By checking the code of Paypal example, it is not compulsory to implement the willCompletePayment method, you can skip this method and directly write didCompletePayment
in this way your code can be like this:
- (void)payPalPaymentViewController:(PayPalPaymentViewController *)paymentViewController didCompletePayment:(PayPalPayment *)completedPayment {
NSLog(#"PayPal Payment Success!");
self.resultText = [completedPayment description];
[self showSuccess];
[self sendCompletedPaymentToServer:completedPayment]; // Payment was processed successfully; send to your server for verification and fulfillment
[self dismissViewControllerAnimated:YES completion:nil];
}
Code documentation for the didCompletePayment from Paypal
Your code MAY deal with the completedPayment, if it did not already do
so within your optional
payPalPaymentViewController:willCompletePayment:completionBlock:
method.
By using that method you don't need to call willCompletePayment method and you will not face the issue which you have faced.

Integrating Paypal SDK for iOS

I'm trying to integrate the PayPal sdk for iOS app. I have installed it through Cocoapods ... Now I want to link some of the binary files .Should I have to download them and add manually or what is the case? Please let me know the steps to do so...
Thank you...
Follow the below code:-
#import "PayPalMobile.h"
#property(nonatomic, strong, readwrite) PayPalConfiguration *payPalConfig;
#property(nonatomic, strong, readwrite) NSString *environment;
Implement the delegates
<PayPalPaymentDelegate, PayPalFuturePaymentDelegate>
Call the below method named configPaypalPayment and implement the delegate methods as follows:-
#pragma mark - paypal
- (void)configPaypalPayment {
_environment = PayPalEnvironmentSandbox;
[PayPalMobile preconnectWithEnvironment:_environment];
// Set up payPalConfig
_payPalConfig = [[PayPalConfiguration alloc] init];
_payPalConfig.acceptCreditCards = YES;
_payPalConfig.merchantName = #"Andmine";
_payPalConfig.merchantPrivacyPolicyURL = [NSURL URLWithString:#"https://www.paypal.com/webapps/mpp/ua/privacy-full&#8221"];
_payPalConfig.merchantUserAgreementURL = [NSURL URLWithString:#"https://www.paypal.com/webapps/mpp/ua/useragreement-full&#8221"];
_payPalConfig.languageOrLocale = [NSLocale preferredLanguages][0];
_payPalConfig.payPalShippingAddressOption = PayPalShippingAddressOptionNone;
}
#pragma mark -
#pragma mark PayPalPaymentDelegate methods
- (void)payPalPaymentViewController:
(PayPalPaymentViewController *)paymentViewController
didCompletePayment:(PayPalPayment *)completedPayment {
NSLog(#"PayPal Payment Success!");
[self sendCompletedPaymentToServer:completedPayment]; // Payment was processed
// successfully; send to
// server for
// verification and
// fulfillment
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)payPalPaymentDidCancel:
(PayPalPaymentViewController *)paymentViewController {
NSLog(#"PayPal Payment Canceled");
// self.resultText = nil;
// self.successView.hidden = YES;
[self dismissViewControllerAnimated: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 - Authorize Future Payments
- (IBAction)getUserAuthorizationForFuturePayments:(id)sender {
PayPalFuturePaymentViewController *futurePaymentViewController =
[[PayPalFuturePaymentViewController alloc]
initWithConfiguration:self.payPalConfig
delegate:self];
[self presentViewController:futurePaymentViewController
animated:YES
completion:nil];
}
#pragma mark PayPalFuturePaymentDelegate methods
- (void)payPalFuturePaymentViewController:
(PayPalFuturePaymentViewController *)futurePaymentViewController
didAuthorizeFuturePayment:
(NSDictionary *)futurePaymentAuthorization {
NSLog(#"PayPal Future Payment Authorization Success!");
// self.resultText = [futurePaymentAuthorization description];
// [self showSuccess];
[self sendFuturePaymentAuthorizationToServer:futurePaymentAuthorization];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)payPalFuturePaymentDidCancel:
(PayPalFuturePaymentViewController *)futurePaymentViewController {
NSLog(#"PayPal Future Payment Authorization Canceled");
// self.successView.hidden = YES;
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)sendFuturePaymentAuthorizationToServer:(NSDictionary *)authorization {
// TODO: Send authorization to server
NSLog(#"Here is your authorization:\n\n%#\n\nSend this to your server to "
#"complete future payment setup.",
authorization);
}

How to integrate PayPal/Apple Pay payment module in iOS App?

I am doing R&D on How to integrate PayPal/Apple Pay payment module in iOS App.
For example in my app i want to integrate PayPal/Apple pay for payment, then what should I do ? What are the process.
IF anyone can guide how to do it. Please suggest me the steps.
Any reference link then also welcome.
It depends on the payment solution you've integrated.
PayPal will support funding source of account balance or credit card/debit card/bank that is linked to the account. While unlike the PayPal wallet, there's no "balance" thing in the Apple Pay/Apple Wallet, which works purely with card tokenization (cards that you setup in your Wallet App).
In this use case, your app won't necessarily to check whether $20 is available in the wallet (either PayPal or Apple Pay), instead it will initiate the payment request, and get the response from the payment gateway to process your orders
in AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[PayPalMobile initializeWithClientIdsForEnvironments:#{PayPalEnvironmentProduction : #"YOUR_CLIENT_ID_FOR_PRODUCTION",
PayPalEnvironmentSandbox : #"AeB0tbkw-z4Ys3NvxekUZxnVNk26WXRodQBETFG4x-HtQAuqBf5k4edWOn2zia_l8RWBFJGEUNSVWJWg"}];
return YES;
}
with your Controller
in your .h File set delegate
#interface MyCart : UITableViewController
#property(nonatomic, strong, readwrite) PayPalConfiguration *payPalConfig;
in your .m File
- (void)viewDidLoad {
NSString *environment=#"sandbox";
self.environment = environment;
[PayPalMobile preconnectWithEnvironment:environment];
_payPalConfig = [[PayPalConfiguration alloc] init];
_payPalConfig.acceptCreditCards = YES;
_payPalConfig.merchantName = #"ScanPay";
_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];
_payPalConfig.payPalShippingAddressOption = PayPalShippingAddressOptionPayPal;
}
Code with purchase button event
-(IBAction)btnCheckoutTapped
{
// UIAlertView *alt=[[UIAlertView alloc]initWithTitle:#"ScanPay" message:#"Under Development" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
// [alt show];
NSDecimalNumber *subtotal = [[NSDecimalNumber alloc]initWithDouble:Price];
// Optional: include payment details
NSDecimalNumber *shipping = [[NSDecimalNumber alloc] initWithString:#"0.00"];
NSDecimalNumber *tax = [[NSDecimalNumber alloc] initWithString:#"0.00"];
PayPalPaymentDetails *paymentDetails = [PayPalPaymentDetails paymentDetailsWithSubtotal:subtotal
withShipping:shipping
withTax:tax];
NSDecimalNumber *total = [[subtotal decimalNumberByAdding:shipping] decimalNumberByAdding:tax];
PayPalPayment *payment = [[PayPalPayment alloc] init];
payment.amount = total;
payment.currencyCode = #"USD";
payment.shortDescription = #"You Pay";
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 = YES;
PayPalPaymentViewController *paymentViewController = [[PayPalPaymentViewController alloc] initWithPayment:payment
configuration:self.payPalConfig
delegate:self];
[self presentViewController:paymentViewController animated:YES completion:nil];
}
PayPalPaymentDelegate methods
- (void)payPalPaymentViewController:(PayPalPaymentViewController *)paymentViewController didCompletePayment:(PayPalPayment *)completedPayment {
NSLog(#"PayPal Payment Success!");
[self ErrorWithString:#"PayPal Payment Success!"];
self.resultText = [completedPayment description];
//[self showSuccess];
[self sendCompletedPaymentToServer:completedPayment]; // Payment was processed successfully; send to server for verification and fulfillment
[self dismissViewControllerAnimated:YES completion:nil];
ReceiptScreen *obj=[self.storyboard instantiateViewControllerWithIdentifier:#"ReceiptScreen"];
[self.navigationController pushViewController:obj animated:YES];
}
- (void)payPalPaymentDidCancel:(PayPalPaymentViewController *)paymentViewController {
NSLog(#"PayPal Payment Canceled");
self.resultText = nil;
// self.successView.hidden = YES;
[self dismissViewControllerAnimated: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);
}
PayPal - Here is complete PayPal sample code suggested by https://developer.paypal.com, PayPal Developer Guide and Sample code
Apple Pay - You can check it apple's demo code
I hope you are looking for it. :)

PayPal iOS SDK 2.0.5 is not authenticating email id and password correctly

hii everyone i am new on this professional site.actually i have a problem in PayPal iOS SDK 2.0.5. This sdk is downloaded from github and now when I tried to logged in paypal then it is not authenticating Can anyone tell that why is this happening and payment is also not transferred in business account from personal account
Thankx
Please help me
here is the link
https://github.com/paypal/PayPal-iOS-SDK/archive/master.zip
#define kPayPalEnvironment PayPalEnvironmentNoNetwork
#interface ZZMainViewController ()
#property(nonatomic, strong, readwrite) IBOutlet UIButton *payNowButton;
#property(nonatomic, strong, readwrite) IBOutlet UIButton *payFutureButton;
#property(nonatomic, strong, readwrite) IBOutlet UIView *successView;
#property(nonatomic, strong, readwrite) PayPalConfiguration *payPalConfig;
#end
#implementation ZZMainViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = #"PayPal SDK Demo";
// Set up payPalConfig
_payPalConfig = [[PayPalConfiguration alloc] init];
_payPalConfig.acceptCreditCards = YES;
_payPalConfig.languageOrLocale = #"en";
_payPalConfig.merchantName = #"Awesome Shirts, 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"];
// 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.
_payPalConfig.languageOrLocale = [NSLocale preferredLanguages][0];
// Do any additional setup after loading the view, typically from a nib.
self.successView.hidden = YES;
// use default environment, should be Production in real life
self.environment = kPayPalEnvironment;
NSLog(#"PayPal iOS SDK version: %#", [PayPalMobile libraryVersion]);
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:YES];
// Preconnect to PayPal early
[PayPalMobile preconnectWithEnvironment:self.environment];
}
#pragma mark - Receive Single Payment
- (IBAction)pay {
// Remove our last completed payment, just for demo purposes.
self.resultText = 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.
}
// 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];
}
- (void)payPalPaymentViewController:(PayPalPaymentViewController *)paymentViewController didCompletePayment:(PayPalPayment *)completedPayment {
NSLog(#"PayPal Payment Success!");
self.resultText = [completedPayment description];
[self showSuccess];
[self sendCompletedPaymentToServer:completedPayment]; // Payment was processed successfully; send to server for verification and fulfillment
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)payPalPaymentDidCancel:(PayPalPaymentViewController *)paymentViewController {
NSLog(#"PayPal Payment Canceled");
self.resultText = nil;
self.successView.hidden = YES;
[self dismissViewControllerAnimated: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 c onfirmation and fulfillment.", completedPayment.confirmation);
}
#pragma mark - Authorize Future Payments
- (IBAction)getUserAuthorization:(id)sender {
PayPalFuturePaymentViewController *futurePaymentViewController = [[PayPalFuturePaymentViewController alloc] initWithConfiguration:self.payPalConfig delegate:self];
[self presentViewController:futurePaymentViewController animated:YES completion:nil];
}
#pragma mark PayPalFuturePaymentDelegate methods
- (void)payPalFuturePaymentViewController:(PayPalFuturePaymentViewController *)futurePaymentViewController didAuthorizeFuturePayment:(NSDictionary *)futurePaymentAuthorization {
NSLog(#"PayPal Future Payment Authorization Success!");
self.resultText = futurePaymentAuthorization[#"code"];
[self showSuccess];
[self sendAuthorizationToServer:futurePaymentAuthorization];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)payPalFuturePaymentDidCancel:(PayPalFuturePaymentViewController *)futurePaymentViewController {
NSLog(#"PayPal Future Payment Authorization Canceled");
self.successView.hidden = YES;
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)sendAuthorizationToServer:(NSDictionary *)authorization {
// TODO: Send authorization to server
NSLog(#"Here is your authorization:\n\n%#\n\nSend this to your server to complete future payment setup.", authorization);
}
#pragma mark - Helpers
- (void)showSuccess {
self.successView.hidden = NO;
self.successView.alpha = 1.0f;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:2.0];
self.successView.alpha = 0.0f;
[UIView commitAnimations];
}
#pragma mark - Flipside View Controller
- (void)flipsideViewControllerDidFinish:(ZZFlipsideViewController *)controller {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
[self dismissViewControllerAnimated:YES completion:nil];
} else {
[self.flipsidePopoverController dismissPopoverAnimated:YES];
self.flipsidePopoverController = nil;
}
}
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
self.flipsidePopoverController = nil;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"pushSettings"]) {
[[segue destinationViewController] setDelegate:self];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
UIPopoverController *popoverController = [(UIStoryboardPopoverSegue *)segue popoverController];
self.flipsidePopoverController = popoverController;
popoverController.delegate = self;
}
}
}
- (IBAction)togglePopover:(id)sender {
if (self.flipsidePopoverController) {
[self.flipsidePopoverController dismissPopoverAnimated:YES];
self.flipsidePopoverController = nil;
} else {
[self performSegueWithIdentifier:#"showAlternate" sender:sender];
}
}
#end
You are not authenticating the email and password because you have your environment set to PayPalEnvironmentNoNetwork. Setting it to NoNetwork sets it to a "mock" environment and just simulates the actions. You'll need to set the environment to either Live or Sandbox in order to process/authenticate with those environments. The below code is the relevant snippet that you need to look at...
// Set the environment:
// - For live charges, use PayPalEnvironmentProduction (default).
// - To use the PayPal sandbox, use PayPalEnvironmentSandbox.
// - For testing, use PayPalEnvironmentNoNetwork.
#define kPayPalEnvironment PayPalEnvironmentSandbox

TRANSACTION_REFUSED - The transaction was refused. in paypal ios sdk

I am using following code in appdelegate
[PayPalMobile initializeWithClientIdsForEnvironments:#{PayPalEnvironmentProduction : #"some client id"}];
And using this code for paypalpayment
#define kPayPalEnvironment PayPalEnvironmentProduction
- (void)viewDidLoad
{
[super viewDidLoad];
// Set up payPalConfig
_payPalConfig = [[PayPalConfiguration alloc] init];
_payPalConfig.acceptCreditCards = YES;
_payPalConfig.languageOrLocale = #"en";
_payPalConfig.merchantName = #"Anything";
_payPalConfig.languageOrLocale = [NSLocale preferredLanguages][0];
// Do any additional setup after loading the view, typically from a nib.
// use default environment, should be Production in real life
self.environment = kPayPalEnvironment;
NSLog(#"PayPal iOS SDK version: %#", [PayPalMobile libraryVersion]);
}
- (IBAction)btnPaypalClicked:(UIButton *)sender
{
PayPalPayment *payment = [[PayPalPayment alloc] init];
payment.amount = [[NSDecimalNumber alloc] initWithString:#"5"];
payment.currencyCode = #"GBP";
payment.shortDescription = #"anything";
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];
}
- (void)payPalPaymentViewController:(PayPalPaymentViewController *)paymentViewController didCompletePayment:(PayPalPayment *)completedPayment
{
NSLog(#"PayPal Payment Success!");
NSLog(#"%#",completedPayment);
[self saveCompletedPayment:completedPayment]; // Payment was processed successfully; send to server for verification and fulfillment
[self dismissViewControllerAnimated:YES completion:nil];
}
I am using all above codes for paypal payment.
but when i pay it shows following error
TRANSACTION_REFUSED - The transaction was refused.
I have balance in my paypal account but still getting this error.
Is there anything still i am missing.
Please help me to solve this issue.
Thanks in advance.
Please see discussion at https://github.com/paypal/PayPal-iOS-SDK/issues/111 The reason for decline is Unfortunately the payment couldn't be completed with the funding source chosen. Please attempt with a different funding option.

Resources