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

を呼び出すためにその に処理を完了した後に完了ブロックを返却する必要があります

あなたのコードはcompletionBlockを呼び出して終了しなければなりません。
completionBlock処理が完了したときに実行するブロック。

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

別のオプション で:あなたはこのようにすることができ、それはdidCompletePaymentに行きます。この完了ブロックを、書き込み後

ので、あなたのコードは

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

のようになりますPaypalのコードをチェックすると、willCompletePaymentメソッドを実装することは義務ではなく、このメソッドをスキップして直接書き込むことができますそれはまだ行っていない場合はあなたのコードは、completedPaymentに対処するかもしれ

ペイパル

から 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]; 
} 

コードのドキュメント:あなたのコードは、このようにすることができ、このように電子didCompletePayment

したがって、任意の payPalPaymentViewController:willCompletePayment:completionBlock: メソッド内にあります。

この方法を使用すると、willCompletePaymentメソッドを呼び出す必要はなく、直面した問題に直面することはありません。

+0

ありがとう、それは全ライフセーバーです。 –