在 iPhone 应用程序中使用 PayPal API
您好,我想在我的 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 集成的例子。
我也想使用结账功能。我是这个领域的新手,所以我对此一无所知。所以,请给我完整的示例代码。 提前致谢。
Hello I want to use Paypal in my iphone application, I have find the soapRequest to integrating the paypal API. My code is
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");
}
But here I am not getting the value of paypalUrlNVP. How can i get it??
And if possible then please give some example of paypalAPI integration in iphone.
I also want to use checkout functionality.I am new in this field so I have no idea about it. So, kindly give me whole sample code.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您似乎混淆了调用 PayPal API 的两种不同方式。您有一个 SOAP XML 字符串,但您实际上并不使用该字符串,而是调用 NVP(名称值对)API。
您需要决定实际要使用哪个。
NVP API 需要使用的 URL 是:
如此处所述:
https://cms.paypal.com/us/cgi-bin/?cmd=_render- content&content_ID=developer/e_howto_api_nvp_NVPAPI概述
You appear to be mixing up two different ways of calling the PayPal API. You have a SOAP XML string, which you don't actually use and also then call the NVP (name value pair) API.
You need to decide which you are actually going to use.
The URLs you need to use for the NVP API are:
As described here:
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_nvp_NVPAPIOverview
此外,我认为您应该对传入的名称和值参数进行 URL 编码。
Additionally, I think you should URL-encode the name and value parameters that you're passing in.
您可能也想看看这个问题(链接),这表明您会< /em> 您的申请被 Apple 拒绝。您需要查看应用程序内购买机制以在 iPhone 应用程序中收取付款
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