关于在iphone中从paypal获取交易ID

时间:2011-09-20 09:28:41

标签: iphone ios ipad paypal

我已经在我的iphone项目中实现了paypal库付款。

如何在成功调用以下方法后检索事务ID。

-(void)paymentSuccessWithKey:(NSString *)payKey andStatus:(PayPalPaymentStatus)paymentStatus {
    status = PAYMENTSTATUS_SUCCESS;
}

- (void)paymentLibraryExit 
{
    UIAlertView *alert1 = nil;

    switch (status) 
        {           
        case PAYMENTSTATUS_SUCCESS:            
                {
                   .......
                   ...........
                }
                ...............
                ..............
         }
}

2 个答案:

答案 0 :(得分:1)

以下方法中的“payKey”是transactionID。

-(void)paymentSuccessWithKey:(NSString *)payKey andStatus:(PayPalPaymentStatus)paymentStatus {
    status = PAYMENTSTATUS_SUCCESS;
}

答案 1 :(得分:0)

最后,我通过api使用paykey获得了交易ID,其中包含以下api详细信息: - https://www.x.com/developers/paypal/documentation-tools/api/paymentdetails-api-operation

您可以通过解析以下api请求代码的响应数据来获取事务ID: -

- (void)paymentSuccessWithKey:(NSString *)payKey andStatus:(PayPalPaymentStatus)paymentStatus {
    status = PAYMENTSTATUS_SUCCESS;

    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://svcs.paypal.com/AdaptivePayments/PaymentDetails"]];

    NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:url];


    NSString *parameterString = [NSString stringWithFormat:@"payKey=%@&requestEnvelope.errorLanguage=%@",payKey,@"en_US"];

    NSString *msgLength = [NSString stringWithFormat:@"%d", [parameterString length]];

    [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];

    //do post request for parameter passing 
    [theRequest setHTTPMethod:@"POST"];

    [theRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];

    //passing key as a http header request 
    [theRequest addValue:api_username forHTTPHeaderField:@"X-PAYPAL-SECURITY-USERID"];

    //passing key as a http header request
    [theRequest addValue:api_password forHTTPHeaderField:@"X-PAYPAL-SECURITY-PASSWORD"];

    [theRequest addValue:api_signature forHTTPHeaderField:@"X-PAYPAL-SECURITY-SIGNATURE"];

    [theRequest addValue:@"NV" forHTTPHeaderField:@"X-PAYPAL-REQUEST-DATA-FORMAT"];

    [theRequest addValue:@"NV" forHTTPHeaderField:@"X-PAYPAL-RESPONSE-DATA-FORMAT"];

    [theRequest addValue:app_id forHTTPHeaderField:@"X-PAYPAL-APPLICATION-ID"];

    [theRequest setHTTPBody: [parameterString dataUsingEncoding:NSUTF8StringEncoding]];

    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

    if( connection )
    {
        webData = [[NSMutableData data] retain];
    }
    else
    {
        NSLog(@"theConnection is NULL");
    }
}