Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 4    Views: 90

magister
I hate code!
Profile
Posts: 66
Reg: Feb 16, 2012
firenze
660
03/08/12 04:04 PM (13 years ago)

Insert Pay Button with Plugin?

I need to make a call to a payment gateway with a button action that integrates their code in my Buzztouch project. What is the best way to go about it? Work on the . h and .m files of a blank plugin? Just for a button action? Or is there a simpler way?
 
Merchantguy
Aspiring developer
Profile
Posts: 21
Reg: Feb 10, 2012
SLC
210
like
03/09/12 11:23 PM (13 years ago)
I've had success calling an entire screen from the external url option where a php script I host that shows the payment page and submits to gateway and returns response in the screen. That is the easiest if you're more familiar with php. If you're more comfortable with the native side then most payment gateways take a POST string formatted correctly, below is something that should work for the NMI gateway, or any other if you add the additional parameters that your gateway requires: NSString *username = @"demo"; NSString *password = @"password"; NSString *transactAmount = amount.text; NSString *post = [NSString stringWithFormat:@"?username=%@&password=%@&amount=%@", [self urlEncodeValue:username], [self urlEncodeValue:password], [self urlEncodeValue:transactAmount]; NSString *hostStr = @"https://secure.networkmerchants.com/api/transact.php"; hostStr = [hostStr stringByAppendingString:post]; NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]]; NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding]; NSArray *responseData = [serverOutput componentsSeparatedByString:@"&"]; // full Response String NSString *responseTextFull = [responseData objectAtIndex:1]; NSArray *responseTextParts = [responseTextFull componentsSeparatedByString:@"="]; NSString *responseText = [responseTextParts objectAtIndex:1];
 
magister
I hate code!
Profile
Posts: 66
Reg: Feb 16, 2012
firenze
660
like
03/10/12 02:19 AM (13 years ago)
That is very nice of you Merchantguy. Thanks for taking the time to share your code. When programmers work on 'real world' solutions, things get interesting:) I am an Objectiv-C novice and I will have to find out where exactly to put that POST string you mention. My pages in XCode are all in Jquery Mobile and so are the buttons. A Php script could be an easier call, but what about security?
 
Merchantguy
Aspiring developer
Profile
Posts: 21
Reg: Feb 10, 2012
SLC
210
like
03/10/12 11:49 AM (13 years ago)
When you use the plugin of "external URL" or whatever it's called make sure you use ssl and you're good.
 
magister
I hate code!
Profile
Posts: 66
Reg: Feb 16, 2012
firenze
660
like
03/10/12 02:45 PM (13 years ago)
Thanks a lot, I will look at that. (Sounds appealing after a day trying to get XCode 4.3 to talk nice to Jquery.)
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.