有没有人通过本机iPhone应用程序实现PayPal API? [英] Has anyone implemented the PayPal API through a native iPhone app?

查看:95
本文介绍了有没有人通过本机iPhone应用程序实现PayPal API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎唯一的方法是在应用程序中保留paypal移动网站的UIWebView,让他们在那里完成交易,否则用户需要使用他们的API密钥。

It seems the only way to stay "in app" is to give them a UIWebView of the paypal mobile site and let them complete the transaction there, otherwise the user would need to use their API key.

这听起来是否正确,有没有人看到或看到任何示例代码?我必须认为这是一个常见的代码。

Does this sound right and has anyone got or seen any sample code? I have to think this is a common piece of code.

更新:
苹果会允许这样吗?
这是一个慈善应用程序,所以我假设没有问题。

UPDATE: Will Apple allow this? It is a charity app, so I am assuming there is no issue.

重新更新:
我假设错了。
苹果不允许直接在应用程序内使用paypal付款。

Re-UPDATE: I assumed wrong. Apple will not allow payments directly within apps using paypal. You have to re-direct to a web interface.

推荐答案

重新更新:
如下所述,此代码可能仍然对购买实体商品有用

Re-Update: As answered below this code may still be useful for the purchase of physical goods

更新:

虽然此代码适用,但App Store条款不允许您在应用内使用此代码。

Although this code works, App Store terms won't allow you to use this code within an app.

原始回答:

我在一些重要的API研究后想出了这一点。下面是一个创建HTTP POST以发送到Paypal并创建NSURLRequest的方法。您可以填写适当的字符串格式变量。我使用 HTTP Client 检查我在做什么。

I figured this out after some heavy API research. Below is a method that creates an HTTP POST to send to Paypal and makes an NSURLRequest. You can fill in the appropriate string format variables. I used HTTP Client to check what I was doing.

- (void)sendPayPalRequestPOST{

perfomingSetMobileCheckout=YES;
recordResults = FALSE;

NSString *parameterString = [NSString stringWithFormat:@"USER=%@&PWD=%@&SIGNATURE=%@&VERSION=57.0&METHOD=SetMobileCheckout&AMT=%.2f&CURRENCYCODE=USD&DESC=%@&RETURNURL=%@", userName, password, signature, self.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");
}
}

之后,您需要解析响应,抓取会话密钥并创建一个UIWebView将他们带到移动Paypal网站。 Paypal允许你指定一个返回URL,你可以做任何你想要的。只需继续检查此地址的委托方法中的UIWebview,然后知道事务是否完成。

After this you need to parse the response, grab the session key and create a UIWebView to take them to the mobile paypal site. Paypal lets you specify a "return URL" which you can make anything you want. Just keep checking the UIWebview in the delegate method for this address and then you know the transaction is complete.

然后再发送一个HTTP Post(类似于上面的)到Paypal完成交易。您可以在Paypal Mobile Checkout API文档中找到API信息。

Then you send one more HTTP Post (similar to the one above) to Paypal to finalize the transaction. You can find the API information in the Paypal Mobile Checkout API docs.

这篇关于有没有人通过本机iPhone应用程序实现PayPal API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆