2016-03-24 49 views
0

我已經實施了最新的PayPal API,但每次嘗試通過PayPal的沙箱運行支付時,支付都會卡在「處理」上。完全難倒了。謝謝!PayPal支付卡「處理」

-(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 
} 
+1

在哪一步卡住?顯示登錄彈出窗口並在付款後卡住了?他們的演示中是否也會發生這種情況? – HardikDG

+0

登錄窗口很好,憑證已通過,然後它會彈回到您選擇付款的屏幕。我選擇支付,然後它只是停留在處理。在他們的演示中,它對我的​​憑證來說工作得很好。 –

回答

1

您的問題是在willCompletePayment完成塊,你需要你有齊全的加工在 調用didCompletePayment

來自PayPal代碼文檔後返回完成塊

您的代碼必須通過調用completionBlock完成。
completionBlock當您完成處理時執行Block。

所以你的代碼會像

- (void)payPalPaymentViewController:(nonnull PayPalPaymentViewController *)paymentViewController 
       willCompletePayment:(nonnull PayPalPayment *)completedPayment 
        completionBlock:(nonnull PayPalPaymentDelegateCompletionBlock)completionBlock { 
    //do all the code you want 
    completionBlock(); 
} 

後,您寫這完成塊就會去didCompletePayment,可以是這樣的:

- (void)payPalPaymentViewController:(PayPalPaymentViewController *)paymentViewController didCompletePayment:(PayPalPayment *)completedPayment { 
    NSLog(@"PayPal Payment Success!"); 
    self.resultText = [completedPayment description]; 
    [self showSuccess]; 
    [self dismissViewControllerAnimated:YES completion:nil]; 
} 

另一個選項 通過檢查PayPal的代碼示例,實現willCompletePayment方法不是必須的,你可以跳過這個方法直接寫ËdidCompletePayment

這樣你的代碼可以是這樣的:爲didCompletePayment貝寶

- (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]; 
} 

代碼文檔

你的代碼可能處理completedPayment,如果沒有已經做 所以在您的可選 payPalPaymentViewController:willCompletePayment:completionBlock: 方法。

通過使用該方法,您不需要撥打willCompletePayment方法,您將不會面臨您遇到的問題。

+0

非常感謝你 - 總救生員。 –