2015-10-05 145 views
0

我正在嘗試爲iOS應用集成PayPal sdk。我已經通過Cocoapods安裝了它...現在我想鏈接一些二進制文件。我是否必須下載它們並手動添加或者是什麼情況?請讓我知道的步驟,這樣做......爲iOS集成PayPal SDK

謝謝...

+0

請在Google中找到教程。 – Raptor

+0

是的,我已經經歷過這樣的......但我的問題是我們是否必須通過手動解壓縮這些二進制庫或如何鏈接這些二進制庫? –

+0

如果您通過Cocoapods安裝庫,則不需要下載其他文件。只需打開Xcode工作區文件和構建應用程序。 – Raptor

回答

2

按照下面的代碼: -

#import "PayPalMobile.h" 

@property(nonatomic, strong, readwrite) PayPalConfiguration *payPalConfig; 
@property(nonatomic, strong, readwrite) NSString *environment; 

落實代表

<PayPalPaymentDelegate, PayPalFuturePaymentDelegate> 

調用下面的方法名爲configPaypalPayment並實施代理方法如下: -

#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); 
} 
+0

謝謝你,因爲我是iOS新手我想問你,例如我有一個按鈕操作來放置一定的順序和檢查產品,所以我必須創建一個新的viewcontroller類並實現這些方法? –

+0

爲此,您不需要創建新的viewController。在結帳視圖控制器上,調用上面的payPal方法。它會自動彈出payPal視圖並返回結果。 – pkc456

+0

哦,好的..我會試試。謝謝你.. –