ios - PayPal 支付卡住 "processing"

标签 ios objective-c paypal paypal-sandbox

我已经实现了最新的 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
}

最佳答案

你的issue是在willCompletePayment的completion block中,你需要在处理完成后返回completion block 调用 didCompletePayment

来自Paypal代码文档

Your code MUST finish by calling the completionBlock.
completionBlock Block to execute when your processing is done.

所以你的代码会像

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

在你写完这个完成 block 后,它会转到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 的代码文档

Your code MAY deal with the completedPayment, if it did not already do so within your optional payPalPaymentViewController:willCompletePayment:completionBlock: method.

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

关于ios - PayPal 支付卡住 "processing",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36207668/

相关文章:

php - 如何将新的 paypal sdk 添加到 php 中已存在的另一个 paypal sdk 的文件 autoload.php

ios - 更改 UIWebview 框架会更改 iOS9 中的 ScrollView

ios - 错误的 UITableViewAutomaticDimension 高度,仅适用于 iPhone 5

iphone - 所有程序中的 SIGABRT 和 SIGTERM THREAD

objective-c - NSThread 类的对象在没有池的情况下自动释放

payment - 具有定期付款的 ExpressCheckout -- 找不到解决方案

paypal - 回复 paypal 后仍然收到相同的 ipn 消息

ios - 由于方法调用,Tableview 滚动速度变慢

ios - Objective C - 移动图像

objective-c - iPhone : change UITableView cells paint order