As part of integrating a shopping cart with my secure payment provider I need to obtain a hash from a C application which they provide. Can ruby call a C app (sending the order info) and getting the result (a hash)? And if so, is there a neat way that this fits in to the rails framework or do I need to write some custom ruby? Thanks, K.
If it''s command line, might be as simple as result = `/path/to/app --with args` I think I smell Win32? If so, you might want to look at the Win32API library (standard ruby lib). On 07/10/05, Kris Leech <krisleech-BSIDdvZawMx9qp0gCGiW7Q@public.gmane.org> wrote:> As part of integrating a shopping cart with my secure payment provider I > need to obtain a hash from a C application which they provide. > Can ruby call a C app (sending the order info) and getting the result (a > hash)? > > And if so, is there a neat way that this fits in to the rails framework > or do I need to write some custom ruby? > > Thanks, K. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Rasputin :: Jack of All Trades - Master of Nuns
Thanks, but I dont think it is that simple, unfortunatly. The C app is a hash generator supplied with my online payment provider, HSBC. You give it an order and it gives a hash back. You then send the order and hash to their server by SSL. They then, I assume, use the hash to make sure the order was not changed in transit. I dont see the point since it is over SSL, but an order can not be processed without the hash. The rails app will be on freeBSD (textdrive) and will need to call the C app with params and get the resulting hash. Cheers, K. Dick Davies wrote:>If it''s command line, might be as simple as > >result = `/path/to/app --with args` > >I think I smell Win32? If so, you might want to look at the >Win32API library (standard ruby lib). > > >On 07/10/05, Kris Leech <krisleech-BSIDdvZawMx9qp0gCGiW7Q@public.gmane.org> wrote: > > >>As part of integrating a shopping cart with my secure payment provider I >>need to obtain a hash from a C application which they provide. >>Can ruby call a C app (sending the order info) and getting the result (a >>hash)? >> >>And if so, is there a neat way that this fits in to the rails framework >>or do I need to write some custom ruby? >> >>Thanks, K. >>_______________________________________________ >>Rails mailing list >>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> > > >-- >Rasputin :: Jack of All Trades - Master of Nuns >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > > > >-- Interkonect Services UK Ltd. Boundary House Main Street Hoveringham Nottingham NG147 JR web: www.interkonect.com tel: 0115 9663696 fax: 0115 9663696
Kris Leech wrote:> Thanks, but I dont think it is that simple, unfortunatly. > > The C app is a hash generator supplied with my online payment provider, > HSBC. You give it an order and it gives a hash back. You then send the > order and hash to their server by SSL. They then, I assume, use the hash > to make sure the order was not changed in transit. I dont see the point > since it is over SSL, but an order can not be processed without the hash. > > The rails app will be on freeBSD (textdrive) and will need to call the C > app with params and get the resulting hash.Where is the app hosted? What''s it called? How do you currently retrieve the hash manually? -- Alex
The app will be on TextDrive. Its basically a standard shopping cart which need intigrating with HSBC''s process. It is not live yet, not live until I get this part worked out! Thanks, K. Alex Young wrote:>Kris Leech wrote: > > >>Thanks, but I dont think it is that simple, unfortunatly. >> >>The C app is a hash generator supplied with my online payment provider, >>HSBC. You give it an order and it gives a hash back. You then send the >>order and hash to their server by SSL. They then, I assume, use the hash >>to make sure the order was not changed in transit. I dont see the point >>since it is over SSL, but an order can not be processed without the hash. >> >>The rails app will be on freeBSD (textdrive) and will need to call the C >>app with params and get the resulting hash. >> >> > >Where is the app hosted? What''s it called? How do you currently >retrieve the hash manually? > > >-- Interkonect Services UK Ltd. Boundary House Main Street Hoveringham Nottingham NG147 JR web: www.interkonect.com tel: 0115 9663696 fax: 0115 9663696
Kris Leech wrote:> The app will be on TextDrive. Its basically a standard shopping cart > which need intigrating with HSBC''s process. > It is not live yet, not live until I get this part worked out!I meant the C app. What are HSBC''s instructions for retrieving the hash from it? -- Alex
Sorry! Basically the PDF says: "The OrderHash is created with a single library call. A list of (string) data is sent, with the CPI Hash Key, to the library and a resultant OrderHash is returned." The CPI Hash Key is a private key. The "list of data" is just a comma deliminated list of values such as credit card number, name on card and amount. The returned hash has a max. length of 28 characters. You get some C code, which I guess needs compiling server? Many thanks, K. Alex Young wrote:>Kris Leech wrote: > > >>The app will be on TextDrive. Its basically a standard shopping cart >>which need intigrating with HSBC''s process. >>It is not live yet, not live until I get this part worked out! >> >> >I meant the C app. What are HSBC''s instructions for retrieving the hash >from it? > > >-- Interkonect Services UK Ltd. Boundary House Main Street Hoveringham Nottingham NG147 JR web: www.interkonect.com tel: 0115 9663696 fax: 0115 9663696
Oh, right. It''s a C *library* - I thought you said it was an app... Have a look at the pickaxe section on extending ruby: http://www.rubycentral.com/book/ext_ruby.html If that''s a bit terrifying, you could always just write a simple C wrapper app that * takes a string and your ''CPI hashkey'' on the command line * calls out to the library * returns the output then just call out to that app using the `` notation. On 07/10/05, Kris Leech <krisleech-BSIDdvZawMx9qp0gCGiW7Q@public.gmane.org> wrote:> Sorry! > > Basically the PDF says: "The OrderHash is created with a single library > call. A list of (string) data is sent, with the CPI Hash Key, to the > library and a resultant OrderHash is returned." > > The CPI Hash Key is a private key. > > The "list of data" is just a comma deliminated list of values such as > credit card number, name on card and amount. > > The returned hash has a max. length of 28 characters. > > You get some C code, which I guess needs compiling server? > > Many thanks, K. > > > > Alex Young wrote: > > >Kris Leech wrote: > > > > > >>The app will be on TextDrive. Its basically a standard shopping cart > >>which need intigrating with HSBC''s process. > >>It is not live yet, not live until I get this part worked out! > >> > >> > >I meant the C app. What are HSBC''s instructions for retrieving the hash > >from it? > > > > > > > > > -- > Interkonect Services UK Ltd. > Boundary House > Main Street > Hoveringham > Nottingham > NG147 JR > > web: www.interkonect.com > tel: 0115 9663696 > fax: 0115 9663696 > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Rasputin :: Jack of All Trades - Master of Nuns
2005/10/8, Dick Davies <rasputnik-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> Oh, right. It''s a C *library* - I thought you said it was an app... > Have a look at the pickaxe section on extending ruby: > > http://www.rubycentral.com/book/ext_ruby.html >You can use swig http://www.swig.org to easily generate the library wrapper.> If that''s a bit terrifying, you could always just write a simple C wrapper app > that > > * takes a string and your ''CPI hashkey'' on the command line > * calls out to the library > * returns the output > > then just call out to that app using the `` notation. > > On 07/10/05, Kris Leech <krisleech-BSIDdvZawMx9qp0gCGiW7Q@public.gmane.org> wrote: > > Sorry! > > > > Basically the PDF says: "The OrderHash is created with a single library > > call. A list of (string) data is sent, with the CPI Hash Key, to the > > library and a resultant OrderHash is returned." > > > > The CPI Hash Key is a private key. > > > > The "list of data" is just a comma deliminated list of values such as > > credit card number, name on card and amount. > > > > The returned hash has a max. length of 28 characters. > > > > You get some C code, which I guess needs compiling server? > > > > Many thanks, K. > > > > > > > > Alex Young wrote: > > > > >Kris Leech wrote: > > > > > > > > >>The app will be on TextDrive. Its basically a standard shopping cart > > >>which need intigrating with HSBC''s process. > > >>It is not live yet, not live until I get this part worked out! > > >> > > >> > > >I meant the C app. What are HSBC''s instructions for retrieving the hash > > >from it? > > > > > > > > > > > > > > > -- > > Interkonect Services UK Ltd. > > Boundary House > > Main Street > > Hoveringham > > Nottingham > > NG147 JR > > > > web: www.interkonect.com > > tel: 0115 9663696 > > fax: 0115 9663696 > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > -- > Rasputin :: Jack of All Trades - Master of Nuns > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On Oct 7, 2005, at 3:16 PM, Dick Davies wrote:> Oh, right. It''s a C *library* - I thought you said it was an app... > Have a look at the pickaxe section on extending ruby: > > http://www.rubycentral.com/book/ext_ruby.htmlYah.. I wouldn''t bother with this pain.> If that''s a bit terrifying, you could always just write a simple C > wrapper app > that > > * takes a string and your ''CPI hashkey'' on the command line > * calls out to the library > * returns the output > > then just call out to that app using the `` notation.Do this, then see the first reply you got (suggesting you call the external program via `backticks`), to which you responded you didn''t think that would work. It''s simple and easy. Don''t make it hard. --Steve
Thanks for the replies, sorry for my inaccuracy. I know nothing about C, and HSBC documentation is a bit vague. I shall try the techniques you describe. Do C libary''s not need compiling then? How does a libary differ from an application? I would have thought a libary is shared code you include in a C programme? Thanks for the help, K. Stephen Waits wrote:> > On Oct 7, 2005, at 3:16 PM, Dick Davies wrote: > >> Oh, right. It''s a C *library* - I thought you said it was an app... >> Have a look at the pickaxe section on extending ruby: >> >> http://www.rubycentral.com/book/ext_ruby.html > > > Yah.. I wouldn''t bother with this pain. > > >> If that''s a bit terrifying, you could always just write a simple C >> wrapper app >> that >> >> * takes a string and your ''CPI hashkey'' on the command line >> * calls out to the library >> * returns the output >> >> then just call out to that app using the `` notation. > > > Do this, then see the first reply you got (suggesting you call the > external program via `backticks`), to which you responded you didn''t > think that would work. It''s simple and easy. Don''t make it hard. > > --Steve > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >-- Interkonect Services UK Ltd. Boundary House Main Street Hoveringham Nottingham NG147 JR web: www.interkonect.com tel: 0115 9663696 fax: 0115 9663696
On Oct 8, 2005, at 5:23 AM, Kris Leech wrote:> Do C libary''s not need compiling then? How does a libary differ > from an application? I would have thought a libary is shared code > you include in a C programme?Libraries are meant to be linked with your own object code (compiled C) to form an application. They''re basically, themselves, object code along with a directory of some sort - but that''s not so important. You may, or may not, have the source to a library. If you don''t, you need to make sure you have the right binary for your platform. If you do, you''ll need to compile it into a library yourself. Then, compile your own program. Finally, include the library on the link command line to form the application. This is hard to describe in a short email. There have to be some decent tutorials on this out there. Good luck, Steve
Stephen Waits wrote:> > On Oct 8, 2005, at 5:23 AM, Kris Leech wrote: > >> Do C libary''s not need compiling then? How does a libary differ from >> an application? I would have thought a libary is shared code you >> include in a C programme? > > > Libraries are meant to be linked with your own object code (compiled C) > to form an application. They''re basically, themselves, object code > along with a directory of some sort - but that''s not so important. > > You may, or may not, have the source to a library. If you don''t, you > need to make sure you have the right binary for your platform. If you > do, you''ll need to compile it into a library yourself. > > Then, compile your own program. Finally, include the library on the > link command line to form the application. > > This is hard to describe in a short email. There have to be some > decent tutorials on this out there.The chapter called "Extending Ruby" in the second edition of "Programming Ruby" would be a good place to start. Some details of Ruby/C interfacing have changed in Ruby 1.8, so the same chapter in the on-line version of the first edition http://www.rubycentral.com/book/ext_ruby.html might be misleading (also, the second edition takes a more tutorial approach). The reference documentation for Ruby/C interfacing is in the file README.EXT in the Ruby distribution (on the machine I''m writing this on, it''s in the directory C:\ruby\doc\Ruby-1.8.2). As you will see, this is not trivial. There''s also the question of whether or not you would be able to build/install this extension on your host. If your payments provider uses a standard algorithm for generating the hash, there''s probably already a Ruby implementation. Alternatively, as previous posters have suggested, if you can make the C code run from the command line then calling it from Ruby becomes easy. (This would still require you to be able to build/install the binary on your host, though.) Good luck! Justin