This is the documentation for LemonStand V1, which has been discontinued. You can learn more and upgrade your store here.

LemonStand Version 1 Has Been Discontinued

This documentation is for LemonStand Version 1. LemonStand is now offered as a cloud-based eCommerce platform.
You can try the new LemonStand and learn about upgrading here.

Creating a Form for Payment Method

The Payment Method partial contains a form for selecting a suitable payment method from the list of available methods. LemonStand prepares the list of available payment methods basing on the billing information provided by a customer on a Billing Information checkout step. The list of available payments methods is presented by the $payment_methods PHP variable supplied by LemonStand.

Start with creating a new partial. According to the code example in the Checkout Page article, the name of the Billing Information partial should be shop:checkout_payment_method. You can use any other name for a partial in your store.

The following code demonstrates an example of the Payment Method partial code:

<h3>Payment Method</h3>
<? if (count($payment_methods)): ?>
  <p>Please select payment method.</p>
  <? foreach ($payment_methods as $method): ?>
    <input <?= radio_state($method->id == $payment_method->id) ?> id="<?= 'method'.$method->id ?>" 
      type="radio" name="payment_method" value="<?= $method->id ?>"/>
    <label for="<?= 'method'.$method->id ?>">
      <?= h($method->name) ?>
      <? if ($method->description): ?>
        <br/><?= h($method->description) ?>
      <? endif ?>
    </label><br/>
  <? endforeach ?> 
  <input type="hidden" name="checkout_step" value="<?= $checkout_step ?>"/>
  <input type="button" value="Next" onclick="return $(this).getForm().sendRequest(
    'on_action', 
    {update:{'checkout_page': 'checkout_partial'}}
  )"/>
<? else: ?>
  <p>There are no payment methods available for your location. Please contact our sales department.</p>
<? endif ?> 
<h3>Payment Method</h3>
{% if payment_methods %}
  <p>Please select payment method.</p>
  {% for method in payment_methods %}
    <input {{ radio_state(method.id == payment_method.id) }} id="{{ 'method'~method.id }}" 
      type="radio" name="payment_method" value="{{ method.id }}"/>
    <label for="{{ 'method'~method.id }}">
      {{ method.name }}
      {% if method.description %}
        <br/>{{ method.description }}>
      {% endif %}
    </label>
  {% endfor %} 
  <input type="hidden" name="checkout_step" value="{{ checkout_step }}"/>
  <input type="button" value="Next" onclick="return $(this).getForm().sendRequest(
    'on_action', 
    {update:{'checkout_page': 'checkout_partial'}}
  )"/>
{% else %}
  <p>There are no payment methods available for your location. Please contact our sales department.</p>
{% endif %}

The code check, whether its the $payment_methods array, contains any payment methods. If there are no payment options available, the corresponding message is displayed. Otherwise, the foreach PHP loop is used for iterating over the list of payment methods. For each payment method the code outputs a label and a radio button control. The label element contains the payment method name and description. Please note the radio button INPUT element name payment_method and value, corresponding to the payment method option identifier.

The checkout_step hidden field should be used in all checkout partials.

See also:

Next: Creating an Order Review Page
Previous: Creating a Form for Shipping Method
Return to AJAX-driven single-page checkout