开发者

Pass options via PayPal

开发者 https://www.devze.com 2023-03-10 00:32 出处:网络
I\'m creating a simple checkout for a client where the visitor can check out via PayPal. Currently, my HTML form looks like this:

I'm creating a simple checkout for a client where the visitor can check out via PayPal. Currently, my HTML form looks like this:

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"> 
  <fieldset> 
    <input type="hidden" name="cmd" value="_xclick" /> 
    <input type="hidden" name="business" value="sandbox@mcbwebdesign.co.uk" /> 
    <input type="hidden" name="item_number" value="29" /> 
    <input type="hidden" name="amount" value="17.99" /> 
    <input type="hidden" name="currency_code" value="GBP" /> 
    <input type="hidden" name="lc" value="GB" /> 
    <input type="hidden" name="item_name" value="Cohda Design Limited: Design Filter Tee" /> 
    <dl id="product_options"> 
      <dt><label for="option_selection1">T-shirt size:</label></dt> 
      <dd> 
        <input type="hidden" name="option_name1" value="T-shirt size" /> 
        <select name="option_selection1" id="option_selection1"> 
          <option value="Small">Small</option> 
          <option value="Medium">Medium</option> 
          <option value="Large">Large</option> 
          <option value="Extra Large">Extra Large</option> 
        </select> 
      </dd> 
      <dt><label for="option_selection2">T-shirt colour:</label></dt> 
      <dd> 
        <input type="hidden" name="option_name2" value="T-shirt colour" /> 
        <select name="option_select开发者_C百科ion2" id="option_selection2"> 
          <option value="Machine Gun Grey">Machine Gun Grey</option> 
          <option value="Blood Red">Blood Red</option> 
        </select> 
      </dd> 
    </dl> 
    <label for="quantity">Quantity:</label> 
    <input type="text" name="quantity" value="1" id="quantity" class="numeric" size="2" maxlength="2" /> 
    <input type="submit" value="Buy now with PayPal or credit/debit card" class="button" /> 
  </fieldset> 
</form> 

As you can see, a simply form that passes a product's details to PayPal for checkout. However, I'm having a problem with custom options, namely option_name1, option_selection1 etc.

How can I pass custom information such as selected size and colour et al to PayPal for the client—and administrator—to view? As currently, testing the above with the PayPal sandbox feature I can't see any where anything pertaining to custom options.


option_selectX is the name of the parameter in the IPN message. What you'll want to add to the button is this:

<input type="hidden" name="on0" value="Size">Size
<select name="os0">
<option value="Option 1">Option 1 $10.00</option>
<option value="Option 2">Option 2 $12.00</option>
<option value="Option 3">Option 3 $13.00</option>
</select>
<input type="hidden" name="option_select0" value="Option 1">
<input type="hidden" name="option_amount0" value="10.00">
<input type="hidden" name="option_select1" value="Option 2">
<input type="hidden" name="option_amount1" value="12.00">
<input type="hidden" name="option_select2" value="Option 3">
<input type="hidden" name="option_amount2" value="13.00">

Just add 'on1' and 'os1' for colours, etc. You can create a static button to have a look at the generated code through https://www.paypal.com/buttonfactory


I had trouble passing custom variables as well, and found out that it was the naming convention that I was getting wrong (probably due to outdated docs).

I had been trying to use option_name1 and option_selection, and that wasn't working. After I was this post, I tried option_select0 and option_amount0.

But it wasn't until I finally found this page https://www.paypal.com/us/cgi-bin/webscr?cmd=_pdn_xclick_options_help_outside that I realized it should really be on0 and os0 as the option name and option value variable names.

I hope this saves someone some time!


If I recall correctly, the custom options you're referring to are simply passed back by PayPal to the callback. The premise being you then tie that particular payment to a particular order which would then have all the options you require specified.

I'm not sure if you can get PayPal to do anything with them their end.

Additionally, I don't know how much it has changed, but in my experience the PayPal sandbox can differ significantly from real PayPal, worth noting.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号