Recent

Author Topic: shopping cart or paypal software ?  (Read 10760 times)

jack616

  • Sr. Member
  • ****
  • Posts: 268
shopping cart or paypal software ?
« on: August 30, 2017, 03:00:55 pm »
Has anyone written either a shopping cart or paypal code with lazarus?


Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: shopping cart or paypal software ?
« Reply #1 on: August 30, 2017, 08:25:02 pm »
Here's an excerpt but working, standalone fpweb program that make a payment request via paypal after filling a (static size) cart:
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}{$H+}
  2.  
  3. uses
  4.   classes,fphttpapp,httpdefs,httpprotocol,httproute;
  5.  
  6. procedure Index(ARequest : TRequest; AResponse : TResponse);
  7. var
  8.   i: Integer;
  9.   s: String;
  10. begin
  11.   with AResponse.Contents do begin
  12.     Add('<html>');
  13.     Add('  <head>');
  14.     Add('    <title>Paypal Test Page</title>');
  15.     Add('  </head>');
  16.     Add('  <body>');
  17.     Add('    <h1>Paypal Test Page</h1>');
  18.     Add('    <form action="/pay" method="post">');
  19.     for i := 1 to 3 do begin
  20.         Str(i,s);
  21.         Add('      <label>Item</label><input type="text" name="item_name_' + s + '"/>');
  22.         Add('      <label>Price</label><input type="text" name="amount_' + s + '"/>');
  23.         Add('      <label>Quantity</label><input type="text" name="qty_' + s + '"/>');
  24.         Add('      <br />');
  25.     end;
  26.     Add('      <input type="submit" value="Checkout" />');
  27.     Add('    </form>');
  28.     Add('  </body>');
  29.     Add('</html>');
  30.   end
  31. end;
  32.  
  33. procedure Pay(ARequest : TRequest; AResponse : TResponse);
  34.  
  35.   function StringListToQueryString(sl: TStrings): String;
  36.   var
  37.     i: Integer;
  38.     OldDelimiter      : Char;
  39.     OldStrictDelimiter: Boolean;
  40.   begin
  41.     for i := 0 to sl.Count - 1 do
  42.       sl.ValueFromIndex[i] := HTTPEncode(sl.ValueFromIndex[i]);
  43.     OldDelimiter       := sl.Delimiter;
  44.     OldStrictDelimiter := sl.StrictDelimiter;
  45.     sl.Delimiter       := '&';
  46.     sl.StrictDelimiter := true;
  47.     Result             := sl.DelimitedText;
  48.     sl.Delimiter       := OldDelimiter;
  49.     sl.StrictDelimiter := OldStrictDelimiter;
  50.   end;
  51.  
  52. var
  53.   PaypalParams: String;
  54. begin
  55.   with ARequest.ContentFields do begin
  56.     Values['business']             := 'put.your@email.here';
  57.     Values['cmd']                  := '_cart';
  58.     Values['upload']               := '1';
  59.     Values['currency_code']        := 'USD';
  60.     Values['charset']              := 'utf-8';
  61.     Values['custom']               := 'any custom data you wish to be sent back from notification, optional of course';
  62.     Values['notify_url']           := 'http://where.paypal.should/fire/back/for/notifying/you';
  63.     Values['return']               := 'http://where.paypal.should/redirect/user/after/payment';
  64.     Values['shipping_1']           := 'the chosen shipping method';
  65.     Values['discount_amount_cart'] := '0';
  66.     Values['tax_cart']             := '0';
  67.     Values['first_name']           := 'receiver first name';
  68.     Values['last_name']            := 'receiver last name';
  69.     Values['address1']             := 'address line 1';
  70.     Values['address2']             := 'address line 2';
  71.     Values['zip']                  := '12345';
  72.     Values['city']                 := 'Depok';
  73.     Values['state']                := 'West Java';
  74.     Values['country']              := 'Indonesia';
  75.     Values['night_phone_b']        := '021-112911388';
  76.     Values['email']                := 'receiver@email.address';
  77.   end;
  78.   PaypalParams       := StringListToQueryString(ARequest.ContentFields);
  79.   AResponse.Code     := 301;
  80.   AResponse.CodeText := 'Redirect';
  81.   AResponse.Location := 'https://www.paypal.com/cgi-bin/webscr?' + PaypalParams;
  82. end;
  83.  
  84. begin
  85.   HTTPRouter.RegisterRoute('/',rmAll,@Index);
  86.   HTTPRouter.RegisterRoute('/pay',rmAll,@Pay);
  87.   Application.Port := 9999;
  88.   Application.Initialize;
  89.   Application.Run;
  90. end.
  91.  
Note that I use the new routing system introduced in FPC trunk, please rewrite in webmodule system if you're using latest stable (3.0.2).
« Last Edit: August 30, 2017, 08:35:56 pm by Leledumbo »

jack616

  • Sr. Member
  • ****
  • Posts: 268
Re: shopping cart or paypal software ?
« Reply #2 on: October 02, 2017, 02:53:11 pm »
Thanks lele but I was really looking for a complete solution I could buy or use.


avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: shopping cart or paypal software ?
« Reply #3 on: October 02, 2017, 06:12:21 pm »
I was really looking for a complete solution I could buy or use.
Although I see only Delphi versions, nSoftware mentions "Support for Lazarus IDE and Free Pascal" so you might investigate a little. Probably Delphi version works in Lazarus, but you need to check it out. Anyway, ActiveX version could also be considered with a little work.
https://www.componentsource.com/product/paypal-integrator-delphi/compatibilities
https://www.nsoftware.com/platforms/delphi/
https://www.nsoftware.com/ibiz/paypal/download.aspx

TMS Software supports PayPal in their VCL Cloud pack, but not yet in LCL Cloud Pack which you could use directly from Lazarus. Maybe you can contact them and show interest in having PayPal in LCL version too.
http://www.tmssoftware.com/site/cloudpack.asp
http://www.tmssoftware.com/site/tmslclcloudpack.asp
« Last Edit: October 02, 2017, 07:58:02 pm by avra »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: shopping cart or paypal software ?
« Reply #4 on: October 02, 2017, 07:26:11 pm »
All right, I looked a little more into PayPal and found that it supports SOAP and provides WSDL:
https://developer.paypal.com/docs/classic/api/PayPalSOAPAPIArchitecture/

We should be able to import that into Lazarus with WST. Unfortunately WST runs out of memory even on 64-bit Lazarus and 16GB RAM, so I will report a bug to WST author. Therefore I used Delphi to import WSDL and generate web service access classes. Unfortunately it is not usable from Lazarus. I have attached it anyway, maybe someone will find them useful.

PayPal also provides REST API which could be also used:
https://developer.paypal.com/docs/api/
« Last Edit: October 02, 2017, 08:00:50 pm by avra »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

jack616

  • Sr. Member
  • ****
  • Posts: 268
Re: shopping cart or paypal software ?
« Reply #5 on: October 04, 2017, 12:57:18 pm »
Thanks for all your work Avra

I'm trying to get a few things done quickly (hence my editor thread) so I need solutions now
not problems to be fixed - but I'll certainly keep an eye on this for the future. If I can transfer
stuff out of PHP etc. into lazarus/FPC I'd be a happy bunny though.


avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: shopping cart or paypal software ?
« Reply #6 on: October 05, 2017, 12:43:47 am »
I'm trying to get a few things done quickly (hence my editor thread) so I need solutions now
not problems to be fixed
Then your best bet would be already mentioned nSoftware with it's PayPal Integrator or full E-Commerce solutions for Delphi and Lazarus.
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: shopping cart or paypal software ?
« Reply #7 on: October 12, 2017, 05:38:50 pm »
Has anyone written either a shopping cart or paypal code with lazarus?

I had to implement a shopping cart with multiple types of discounts (eg: straight % off, buy three for the price of two, buy one get one free etc.) for a Java contracting job recently - it was part of the technical test. It wasn't very hard to do. So go for it!! ;-)
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

Trenatos

  • Hero Member
  • *****
  • Posts: 535
    • MarcusFernstrom.com
Re: shopping cart or paypal software ?
« Reply #8 on: October 18, 2017, 09:24:42 pm »
PayPal integration is pretty easy, if you can do the rest of the web development with FPC the PayPal part shouldn't be a problem.

 

TinyPortal © 2005-2018