1

您好,我想在我的 iphone 应用程序中使用 Paypal,我找到了整合 paypal API 的soapRequest。我的代码是

NSString *soapMessage =  [NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" 
"<SOAP-ENV:Envelope xmlns:xsi= \"http://www.w3.org/2001/XMLSchema-instance\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n"
"<SOAP-ENV:Header>\n" 
"<RequesterCredentials xmlns=\"urn:ebay:api:PayPalAPI\">\n" 
"<Credentials xmlns=\"urn:ebay:apis:eBLBaseComponents\">\n" 
"<Username>api_username</Username>\n" 
"<Password>api_password</Password>\n" 
"<Signature/>\n"     
"<Subject/>\n" 
"</Credentials>\n" 
"</RequesterCredentials>\n" 
"</SOAP-ENV:Header>\n" 
"<SOAP-ENV:Body>\n" 
"<specific_api_name_Req xmlns=\"urn:ebay:api:PayPalAPI\">\n" 
"<specific_api_name_Request>\n" 
"<Version xmlns=urn:ebay:apis:eBLBaseComponents”&gt;service_version</Version>\n" 
"<required_or_optional_fields xsi:type=”some_type_here”&gt;\n"                 
"</required_or_optional_fields>\n" 
"</specific_api_name_Request>\n" 
"</specific_api_name_Req>\n" 
"</SOAP-ENV:Body>\n" 
                          "</SOAP-ENV:Envelope>\n"];

NSLog(@"Soap message===%@",soapMessage);


NSString *parameterString = [NSString stringWithFormat:@"USER=%@&PWD=%@&SIGNATURE=%@&VERSION=57.0&METHOD=SetMobileCheckout&AMT=%.2f&CURRENCYCODE=USD&DESC=%@&RETURNURL=%@", userName, password, signature, donationAmount, @"Some Charge", returnCallURL];

NSLog(parameterString);

NSURL *url = [NSURL URLWithString:paypalUrlNVP];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [parameterString length]];

[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [parameterString dataUsingEncoding:NSUTF8StringEncoding]];


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

if( theConnection ){
    webData = [[NSMutableData data] retain];
//  [self displayConnectingView];

}else{
    NSLog(@"theConnection is NULL");
}

但在这里我没有得到 paypalUrlNVP 的价值。我怎么才能得到它??如果可能的话,请举一些在 iphone 中集成 paypalAPI 的例子。

我也想使用结帐功能。我是这个领域的新手,所以我不知道。所以,请给我完整的示例代码。提前致谢。

4

3 回答 3

2

您似乎混淆了调用 PayPal API 的两种不同方式。您有一个 SOAP XML 字符串,您实际上并没有使用它,然后还调用了 NVP(名称值对)API。

您需要决定实际使用哪个。

您需要用于 NVP API 的 URL 是:

用于 API 签名安全的 API 服务器

如果您使用 API 签名,请将请求发布到以下服务器之一:

沙盒: https ://api-3t.sandbox.paypal.com/nvp

直播:https ://api-3t.paypal.com/nvp API 服务器用于 API 证书安全

如果您使用 API 证书,请将请求发布到以下服务器之一:

沙盒: https ://api.sandbox.paypal.com/nvp

直播:https ://api.paypal.com/nvp

如此处所述:

https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_nvp_NVPAPIOverview

于 2009-09-02T10:36:11.157 回答
0

此外,我认为您应该对传入的名称和值参数进行 URL 编码。

于 2009-09-02T14:20:22.820 回答
-1

You might want to look at this question too (link) which indicates you will have your application rejected by Apple. You need to look at the In App Purchase mechanisms to collect payments in an iPhone App

于 2010-02-17T16:03:30.123 回答