2016-03-24 48 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

非常感谢你 - 总救生员。 –