Reputation: 749
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...
Upvotes: 0
Views: 765
Reputation: 8506
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”"];
_payPalConfig.merchantUserAgreementURL = [NSURL URLWithString:@"https://www.paypal.com/webapps/mpp/ua/useragreement-full”"];
_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);
}
Upvotes: 2