1

我想在我的项目中实现 Paypal 支付网关,但是在连续执行以下 IBAction 3 次或更多次后显示 paypal 登录窗口,请告诉我以下代码有什么问题

-(IBAction)initializePaypal:(id)sender
{
    [PayPal initializeWithAppID:@"APP-80W284485P519543T"forEnvironment:ENV_SANDBOX];
    status = PAYMENTSTATUS_CANCELED;
    [PayPal getPayPalInst].shippingEnabled = FALSE;
    [PayPal getPayPalInst].dynamicAmountUpdateEnabled = FALSE;

//for a payment with a single recipient, use a PayPalPayment object

    payment = [[PayPalPayment alloc] init] ;
    payment.recipient = payPalValue.merchantEmail;
    payment.paymentCurrency = payPalValue.currencyCode;
    payment.description = payPalValue.itemName;
    payment.merchantName = @"By Post";
    payment.subTotal = payPalValue.amount;

    [[PayPal getPayPalInst] checkoutWithPayment:payment];

}
4

1 回答 1

1

单击按钮时,您正在调用贝宝初始化。需要 3-4 秒。您在此之前调用了初始化并检查了initializationStatus,然后再次调用,如下面的代码所示

-(IBAction)initializePaypal:(id)sender
{
    if ([PayPal initializationStatus] == STATUS_COMPLETED_SUCCESS)
    {
        status = PAYMENTSTATUS_CANCELED;
        [PayPal getPayPalInst].shippingEnabled = FALSE;
        [PayPal getPayPalInst].dynamicAmountUpdateEnabled = FALSE;

        //for a payment with a single recipient, use a PayPalPayment object

        payment = [[PayPalPayment alloc] init] ;
        payment.recipient = payPalValue.merchantEmail;
        payment.paymentCurrency = payPalValue.currencyCode;
        payment.description = payPalValue.itemName;
        payment.merchantName = @"By Post";
        payment.subTotal = payPalValue.amount;

        [[PayPal getPayPalInst] checkoutWithPayment:payment];
    }
    else
    {
        NSLog(@"initialization failed");// show alert or "reintialising paypal"
    }
}
于 2013-11-20T06:18:00.210 回答