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 Payment Page

The Pay page is displayed after the Checkout page and displays a payment form or payment instructions. LemonStand automatically redirects browser to the Pay page after the Order Review checkout page. To find the Pay page LemonStand looks for a page with the shop:pay action.

Start with creating a new page. Assign it a name and URL. The name and URL could be anything, for example Pay and /pay correspondingly. Click the Action tab and select the shop:pay action in the action drop-down menu.

The shop:pay action loads an order object into $order variable which is available in the page code. Also the action loads a selected payment method into $payment_method variable.

Usually the Pay page displays the order details above the payment form. Also, the check should be performed in order to determine whether an order is paid yet or not. The following code snippet outputs order details and payment for or payment instructions.

<h2>Pay</h2>
<? if ($order->payment_processed()): ?>
  <p>This order is already paid. Thank you!</p>
<? else: ?>
  <p>
    Order #<?= $order->id ?><br/>
    Total: <?= format_currency($order->total) ?><br/>
    Payment method: <?= h($payment_method->name) ?>
  </p>
  <? if ($order->payment_method->has_payment_form()): ?>
    <? $payment_method->render_payment_form($this) ?>
  <? else: ?>
    <? if ($message = $payment_method->pay_offline_message()): ?>
      <p><?= h($message) ?></p>
    <? else: ?>
      <p>Payment method "<?= h($payment_method->name) ?>" has no payment form.</p>
    <? endif ?>
  <? endif ?>
<? endif ?>
<h2>Pay</h2>
{% if order.payment_processed() %}
  <p>This order is already paid. Thank you!</p>
{% else %}
  <p>
    Order: #{{ order.id }}<br/>
    Total: {{ order.total|currency }}<br/>
    Payment method: {{ payment_method.name }}      
  </p>
  {% if order.payment_method.has_payment_form() %}
    {{ payment_method.render_payment_form(this) }}
  {% else %}
    {% set message = payment_method.pay_offline_message() %}
    {% if message %}
      <p>{{ message }}</p>
    {% else %}
      <p>Payment method "{{ payment_method.name }}" has no payment form.</p>    
    {% endif %}
  {% endif %}
{% endif %}

The code checks whether the order is paid using the payment_processed method of the $order object. If order payment is already processed, the corresponding message is displayed. Otherwise the code outputs the order details (order number, total and payment method) and displays the payment form or payment instructions.

Some payment methods,such as a wire transfer, do not have a payment form. The code uses the has_payment_form method of the $payment_method object to determine whether a payment form is present in a given payment method.

If the payment form is not present, the code outputs  payment instructions, using the pay_offline_message method of the $payment_method object. If there are no payment instructions provided by a payment method, then a default payment instruction is displayed.

If the payment for is present by a given payment method, it is rendered using the render_payment_form method of the $payment_method object. A payment form is provided by a specific payment method as a partial. Payment partials are installed automatically when LemonStand discovers a new payment method installed. When you call the render_payment_form method, it renders a payment form partial, provided by a payment method. In accordance with the naming convention, the payment form partials have names like “payment:paypal_standard”. The payment: part of the name is static, while the second part is different for different payment methods. You can modify the payment form partials, but you should not change the programming-related things like input control's names or Ids, button names and AJAX request codes.

See also:

Next: Creating a Payment Receipt Page
Previous: Payment
Return to Payment