objective-c 有没有人通过本机 iPhone 应用程序实现 PayPal API?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/779423/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 21:26:14  来源:igfitidea点击:

Has anyone implemented the PayPal API through a native iPhone app?

iphoneobjective-ccocoa-touchpaypal

提问by Corey Floyd

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.

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

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 会允许这样做吗?这是一个慈善应用程序,所以我假设没有问题。

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

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

采纳答案by Corey Floyd

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.

尽管此代码有效,但 App Store 条款不允许您在应用程序中使用此代码。



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 Clientto check what I was doing.

经过一些大量的 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");
}
}

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.

在此之后,您需要解析响应,获取会话密钥并创建一个 UIWebView 以将它们带到移动 paypal 站点。Paypal 允许您指定一个“返回 URL”,您可以在其中设置任何您想要的内容。只需继续检查此地址的委托方法中的 UIWebview,然后您就知道交易已完成。

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.

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

回答by Chris Milne

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.

Apple 将允许对实体购买进行自定义结账。我在伦敦的 iPhone Tech Talks 上与他们交谈过,他们说他们将不支持通过 In App Purchase 进行实体购买,因为他们必须处理退款等问题。他们还提到了具有自定义结账功能的现有应用程序。

回答by Vivian Spencer

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

不能使用 Paypal 的移动支付库吗?

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

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

回答by Brent

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

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

回答by Brent

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.

当您说“我假设错了”关于 Apple 允许在应用程序中进行慈善捐赠时,您能提供更多信息吗?我正在开发一个应用程序,并且要求允许慈善捐赠......我无法从 Apple 中找到任何严格禁止它的内容,但我一直无法找到允许慈善捐赠的应用程序商店,要么。

(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).

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