【问题标题】:PayPal payment stuck "processing"贝宝支付卡在“处理中”
【发布时间】:2016-03-24 18:39:00
【问题描述】:

我已经实现了最新的 PayPal API,但每次我尝试通过 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
}

【问题讨论】:

  • 卡在哪一步了?是否显示了登录弹出窗口并且在付款后它被卡住了?在他们的演示中也使用您的凭据吗?
  • 登录窗口正常,凭据通过,然后它会弹回您选择付款的屏幕。我选择付款,然后它只是卡在处理中。在他们的演示中,它与我的凭据一起工作得很好。

标签: ios objective-c paypal paypal-sandbox


【解决方案1】:

您的问题在willCompletePayment的完成块中,您需要在完成处理后返回完成块 拨打didCompletePayment

来自 Paypal 代码文档

您的代码必须通过调用 completionBlock 来完成。
completionBlock 处理完成时执行的块。

所以你的代码会像

- (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

这样你的代码可以是这样的:

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

来自 Paypal 的 didCompletePayment 的代码文档

您的代码可能会处理已完成的付款(如果尚未处理) 所以在你的可选范围内 payPalPaymentViewController:willCompletePayment:completionBlock: 方法。

通过使用该方法,您无需调用willCompletePayment 方法,您将不会遇到您遇到的问题。

【讨论】:

  • 非常感谢 - 完全的救命稻草。
猜你喜欢
  • 2013-04-22
  • 2015-06-25
  • 2011-09-19
  • 2011-01-08
  • 2015-05-02
  • 2015-05-13
  • 1970-01-01
  • 1970-01-01
  • 2016-04-19
相关资源
最近更新 更多