简体   繁体   English

在iPhone应用程序中使用PayPal API

[英]Using the PayPal API in an iPhone application

Hello I want to use Paypal in my iphone application, I have find the soapRequest to integrating the paypal API. 您好,我想在我的iPhone应用程序中使用Paypal,我找到了soapRequest来集成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. 但是,这里我没有得到paypalUrlNVP的价值。 How can i get it?? 我怎么才能得到它?? And if possible then please give some example of paypalAPI integration in iphone. 如果可能的话,请举一些在iPhone中集成paypalAPI的示例。

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. 提前致谢。

You appear to be mixing up two different ways of calling the PayPal API. 您似乎混淆了两种调用PayPal API的方式。 You have a SOAP XML string, which you don't actually use and also then call the NVP (name value pair) API. 您有一个实际上并不使用的SOAP XML字符串,然后还调用了NVP(名称/值对)API。

You need to decide which you are actually going to use. 您需要确定实际使用哪个。

The URLs you need to use for the NVP API are: 您需要用于NVP API的URL是:

API Servers for API Signature Security 用于API签名安全性的API服务器

If you use an API signature, post the request to one ofthese servers: 如果您使用API​​签名,请将请求发布到以下服务器之一:

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

Live: https://api-3t.paypal.com/nvp API Servers for API Certificate Security 实时: https ://api-3t.paypal.com/nvp用于API证书安全的API服务器

If you use an API certificate, post the request to oneof these servers: 如果您使用API​​证书,请将请求发布到以下服务器之一:

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

Live: https://api.paypal.com/nvp 直播: 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 https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_nvp_NVPAPI概述

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

You might want to look at this question too ( link ) which indicates you will have your application rejected by Apple. 您可能也想看一下这个问题( 链接 ),该问题表明您的应用程序被Apple拒绝。 You need to look at the In App Purchase mechanisms to collect payments in an iPhone App 您需要查看“应用内购买”机制才能在iPhone应用中收款

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM