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

5

36

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.

Inveigh answered 22/4, 2009 at 21:57 Comment(3)
Does this mean that it is not possible to purchase real-world goods within an app? Do you mean that one should open Safari to complete the transaction, or can it be done in a UIWebView?Cinchonism
according to an answer below, this may be ok for physical goods. Opening safari is of course always possible. If using the paypal API, you only need to open the WebView to "complete" the tansaction. Everything else can be native.Inveigh
You MUST use in app purchases for virtual goods only. You can NOT use in app purchases for real world goods. You can however use an external method (like PayPal or Stripe) for real world goods.Uria
I
23

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.

Inveigh answered 12/5, 2009 at 2:40 Comment(1)
i am developing App for Car cleaning searvice apple will allow for direct payment of paypal ???Smallman
D
3

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.

Difficulty answered 10/12, 2009 at 15:29 Comment(0)
H
1

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

Houle answered 28/7, 2009 at 22:34 Comment(1)
Thanks for the update Corey. We're not using PayPal, but I'm still expecting to be rejected. I've seen a number of apps that allow you to enter a credit card to buy something (or even just run through a random credit card transaction), but never to donate. Thanks again, and good luck with your app.Houle
D
1

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

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

Disconcert answered 10/8, 2010 at 11:36 Comment(0)
J
1

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

Jaf answered 12/3, 2013 at 16:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.