在 iPhone 应用程序中使用 PayPal API

发布于 2024-08-03 19:46:08 字数 2597 浏览 2 评论 0原文

您好,我想在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

难忘№最初的完美 2024-08-10 19:46:08

您似乎混淆了调用 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_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:

API Servers for API Signature Security

If you use an API signature, post the
request to one ofthese servers:

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

Live: https://api-3t.paypal.com/nvp
API Servers for API Certificate
Security

If you use an API certificate, post
the request to oneof these servers:

Sandbox:
https://api.sandbox.paypal.com/nvp

Live: https://api.paypal.com/nvp

As described here:

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

谁的新欢旧爱 2024-08-10 19:46:08

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

Additionally, I think you should URL-encode the name and value parameters that you're passing in.

爱的十字路口 2024-08-10 19:46:08

您可能也想看看这个问题(链接),这表明您会< /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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文