Paypal button script not working

I am using the following script to add an item to a paypal shopping carton my web app. The script is placed into the URL property of the HTML Viewer control, but when I launch the app, the browser reports an error. Any clues why the following code doesn’t work;

[code]dim ht as string
ht="<script" async="'async"
ht=ht+" src=https://www.paypalobjects.com/js/external/paypal-button-minicart.min.js?merchant=merchantname@merchantdomain.com"
ht=ht+“data-button=cart”
ht=ht+“data-name=Itemname”
ht=ht+“data-amount=190”
ht=ht+“data-shipping=96”
ht=ht+“data-shipping2=90”
ht=ht+“data-number=C”
ht=ht+“data-currency=Eur”
ht=ht+">"

hv.URL=ht[/code]

Try adding " + Endofline.UNIX" to the end of each line

Each of those parameters that you are adding needs to have a & before it, like this:

ht=ht+"&data-button=cart" ht=ht+"&data-name=Itemname"

Otherwise they all run together.

I should have noted:The script runs flawlessly in my HTML editor, but can’t get past the second line. If I add the ampersands as Greg suggested the browser has a coronary and Paypal won’t accept the incoming post. Could it be the syntax of the ht="<script" async="'async" line?

[quote=187008:@chris benton]I am using the following script to add an item to a paypal shopping carton my web app. The script is placed into the URL property of the HTML Viewer control, but when I launch the app, the browser reports an error. Any clues why the following code doesn’t work;

[code]dim ht as string
ht="<script" async="'async"
ht=ht+" src=https://www.paypalobjects.com/js/external/paypal-button-minicart.min.js?merchant=merchantname@merchantdomain.com"
ht=ht+“data-button=cart”
ht=ht+“data-name=Itemname”
ht=ht+“data-amount=190”
ht=ht+“data-shipping=96”
ht=ht+“data-shipping2=90”
ht=ht+“data-number=C”
ht=ht+“data-currency=Eur”
ht=ht+">"

hv.URL=ht[/code][/quote]

Use the email link instead. In your buttons, select “View Code”, and click the Email tab. Copy the one line in the URL property.

Excuse my dumbness, I can’t find the ‘email link’ in the object library. I don’t think we are on the same page Michel. This script creates a ‘Add to cart’ server side button and drops down the cart when invoked.

Show us the code that works in the HTML editor and we can show you how it should look in your Xojo code.

Have you tried that in a regular browser before ? This code looks funny. If it is, as I suspect, a series of URL arguments, then it must be URL encoded, with"&" between fields.

Here is the code correctly formatted :

<HTML><BODY><script async="'async" src=https://www.paypalobjects.com/js/external/paypal-button-minicart.min.js?merchant=merchantname@merchantdomain.com&data-button=cart&data-name=Itemname&data-amount=190&data-shipping=96&data-shipping2=90&data-number=C&data-currency=Eur></script></BODY></HTML>

I created an HTML file with just that into it, and it displays very nicely the button in Chrome. Any time you want to display something in the HTMLViewer, it is always better to try that in a regular browser before.

So basically, all you need to do is to paste the code above in an “ht” constant, then your Xojo code will be just the last line of what you posted :

  hv.URL=ht

I agree that the code looks funny especially the <script async="‘async" because there is a single inverted comma mixed with a pair of quotes i.e.’’ ’ " . The code you pasted works in Safari, but it does not produce an ‘add to cart’ button, instead produces a ‘buy it now’ button. This function is regulated by the ‘data-button=cart’ variable.

The most important part is that you were assembling your request without ampersands, which explains why you never got any button. Now seems to me the variable data-button=cart is indeed in the code.

The other approach I was suggesting in my first reply is instead of assembling a request that way, go to your Paypal account and create a button (it is usually in your preferences). There you will be able to set price, shipping, name, sku, make it a cart button, and this will generate the code for you. It may be simpler.

Here is an example of the code created by paypal with the procedure I told you :

[code]



[/code]

It displays very nicely a shopping cart button with the price and shipping charges you had in your code, and if you click on it, you can send me 286 €.

This really is the way to go. It prevents people from fiddling with the page variables before submitting the add to cart request. I’ve had a number of clients who had to deal with customers giving themselves discounts this way. By having a named button instead like Michel’s example that has everything built-in you take away this opportunity for fraud.

[quote=187269:@Michel Bujardet]



[/quote] Thanks Michel, I tried the example you posted and it works on a browser, but not in Xojo. What I want to do is create buttons on the fly, by sucking in parameters and variables from a server side text file. The encrypted value, value="SFKG7W77HAK3Q"> may mean something to Paypal, but its nothing I can work with. considering that I need to create valid cart buttons for over a hundred products, the above example just won't work for me. If I could just get the following code to work in Xojo most of my problems would be solved. BTW Michel, I am not paying 286 € for a gizmo. They can be purchased a lot cheaper on ebay. [code]ht=ht+" src=https://www.paypalobjects.com/js/external/paypal-button-minicart.min.js?merchant=merchantname@merchantdomain.com" ht=ht+">"[/code]

[quote=187624:@chris benton]Thanks Michel, I tried the example you posted and it works on a browser, but not in Xojo. What I want to do is create buttons on the fly, by sucking in parameters and variables from a server side text file. The encrypted value, value=“SFKG7W77HAK3Q”> may mean something to Paypal, but its nothing I can work with. considering that I need to create valid cart buttons for over a hundred products, the above example just won’t work for me. If I could just get the following code to work in Xojo most of my problems would be solved. BTW Michel, I am not paying 286 € for a gizmo. They can be purchased a lot cheaper on ebay.

ht=ht+" src=https://www.paypalobjects.com/js/external/paypal-button-minicart.min.js?merchant=merchantname@merchantdomain.com" ht=ht+"></script>"[/quote]

The code you posted before and that I tried to make conformant to Paypal requirements by adding ampersands is probably your solution, then. Now as I have no idea where you found the specs for that way of building a button, I am afraid you are on your own.

Good luck.

[quote=187629:@Michel Bujardet]Now as I have no idea where you found the specs for that way of building a button, I am afraid you are on your own.

Good luck.[/quote]
From Paypal’s web site, have a look here http://paypal.github.io/JavaScriptButtons/

Much better. Never ask for help without providing the full picture.

I went through the making of a button code, added as I did before and and this works perfectly :

[code]<script async=“async” src=“https://www.paypalobjects.com/js/external/paypal-button-minicart.min.js?merchant=benton@benton.com
data-button=“cart”
data-name=“Gizmo”
data-quantity=“1”
data-amount=“5”
data-currency=“EUR”
data-shipping=“0.89”
data-tax=“0”
data-callback=“http://benton.com/callback

[/code]

I added that in a constant named benton, and did that to load in the HTMLViewer :

HTMLViewer1.loadpage(benton)

Now all you got to do is to replace the values by whatever you want.

Thanks Michel, it finally works, but I see 2 errors I made in the initial implementation;
No start and end in the script
I was using HTMLViewer’s URL property/method instead of LOADPAGE.

As I said before your pricing on Gizmos is still way too high, the Chinese make them much cheaper that you.
Thanks a ton

The following script as originally modified by Michel Bujardet is added to the open event of a HTMLViewer(HV). It produces a ‘add to cart button’ in the client space of hv. When the button is clicked Paypal’s cart is invoked within the client space of hv. What I cannot sort out is how to locate the cart and button within a specific area of the web app host page. Any suggestions would be greatly appreciated. Keep in mind that an ‘add to cart’ should be located in proximity to the product being sold.

[code] dim ht as string
ht="<script async=async src=https://www.paypalobjects.com/js/external/paypal-button-minicart.min.js?merchantName=@merchantDomain.com"
ht=ht+" data-button=cart"+chr(13)
ht=ht+" data-name=Gizmo"+chr(13)
ht=ht+" data-quantity=1"+chr(13)
ht=ht+" data-amount=5"+chr(13)
ht=ht+" data-currency=EUR"+chr(13)
ht=ht+" data-shipping=0.89"+chr(13)
ht=ht+" data-tax=0"+chr(13)

ht=ht+">"
hv.LoadPage(ht)[/code]

About the only relevant thing that I can vary is the button size by adding ht=ht+" data-size=small"+chr(13) while will give you a smaller more elegant looking button.

[code]

benton

















[/code]