有人通过原生 iPhone 应用程序实现了 PayPal API 吗?

发布于 2024-07-17 23:19:50 字数 271 浏览 3 评论 0原文

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

这听起来正确吗?有人得到或看到过任何示例代码吗? 我不得不认为这是一段常见的代码。

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

重新更新: 我以为错了。 Apple 不允许使用 PayPal 在应用程序内直接付款。 您必须重定向到 Web 界面。

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(5

予囚 2024-07-24 23:19:50

重新更新:
正如下面的回答,此代码对于购买实体商品可能仍然有用


更新:

虽然此代码有效,但应用程序商店条款不允许您在应用程序中使用此代码。


原始答案:

我在进行大量 API 研究后发现了这一点。 下面是一个创建 HTTP POST 发送到 Paypal 并发出 NSURLRequest 的方法。 您可以填写适当的字符串格式变量。 我使用 HTTP 客户端 来检查我在做什么。

- (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 允许您指定一个“返回 URL”,您可以在其中进行任何您想要的操作。 只需继续检查委托方法中的 UIWebview 中的该地址,然后您就知道交易已完成。

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

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


Update:

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


Original Answer:

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");
}
}

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.

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.

抱猫软卧 2024-07-24 23:19:50

苹果将​​允许实体购买的自定义结账。 我在伦敦举行的 iPhone 技术讲座上与他们进行了交谈,他们表示他们不会支持通过应用内购买进行实体购买,因为他们必须处理退款等问题。他们还提到了具有自定义结账功能的现有应用程序。

Apple will allow custom checkouts for physical purchases. I talked with them at the iPhone Tech Talks in London and they said that they will not support physical purchases with In App Purchase as they would have to deal with refunds, etc. They also referred to existing apps that have custom checkouts.

滿滿的愛 2024-07-24 23:19:50

当你说“我认为苹果在应用程序内允许慈善捐赠是错误的”时,你能提供更多信息吗? 我正在开发一个应用程序,并且有允许慈善捐赠的要求...我还没有找到苹果公司严格禁止它的任何内容,但我还没有找到一个允许慈善捐赠的应用程序商店,或者。

(我纠结是否要把这个问题发布在这里,而不是作为一个新的顶级问题,但你是我遇到的第一个在 iPhone 应用程序问题中直接了解慈善捐赠的人)。

When you say "I assumed wrong" about Apple allowing charitable donations within an app, can you provide any more information? I'm working on an app and there's a requirement to allow charitable donations...I haven't been able to find anything from Apple strictly forbidding it, but I haven't been able to find an app that allows charitable donations in the store, either.

(I struggled with whether to post this here and not as a new top-level question, but you're the first person I've come across with direct knowledge about the charitable giving within an iPhone app question).

安人多梦 2024-07-24 23:19:50

是否无法使用 Paypal 的移动支付库?

https://www.x.com/community/ppx/ xspaces/mobile/mep?view=概述

Is it not possible using Paypal's Mobile Payment Library?

https://www.x.com/community/ppx/xspaces/mobile/mep?view=overview

尛丟丟 2024-07-24 23:19:50

根据您需求的复杂程度,PayPal 的 iOS SDK(2013 年 3 月发布)可能是门票。

Depending on the complexity of your needs, PayPal's iOS SDK (released March 2013) might be the ticket.

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