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

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

问题描述

似乎保持在应用程序中"的唯一方法是给他们一个贝宝移动网站的 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.

重新更新:我假设错了.Apple 不允许使用 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.

然后您再向 Paypal 发送一个 HTTP Post(类似于上面的那个)以完成交易.您可以在 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天全站免登陆