在iPhone应用程序中使用PayPal API

时间:2009-09-02 10:15:05

标签: iphone objective-c paypal

您好我想在我的iphone应用程序中使用Paypal,我发现soapRequest集成了paypal API。我的代码是

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”>service_version</Version>\n" 
"<required_or_optional_fields xsi:type=”some_type_here”>\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集成的例子。

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

3 个答案:

答案 0 :(得分:2)

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

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

您需要为NVP API使用的网址是:

  

用于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

答案 1 :(得分:0)

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

答案 2 :(得分:-1)

您可能也想查看此问题(link),表明您让Apple拒绝您的申请。您需要查看In App Purchase机制以在iPhone App中收取付款