LemonStand Documentation

Creating the Payment Method partial

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 ?> 

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 the Order Review partial
Previous: Creating the Shipping Method partial
Return to AJAX-driven single-page checkout

Comments

No comments posted so far.

Add your comment

Loading form...