First Order

The payment process consists of two steps: initializePayment with validation and completePayment. Before we can order something, we have to put something into the cart.

Add product to cart

$merx = merx();
$merx->cart()->add(['id' => 'nice-shoes']);

The id has to be a valid page. The page must have a price field.

On another page you should show the customer’s cart.


$merx = merx();
foreach($merx->cart() as $item) {
  $itemPage = page($item['id']);
  echo $itemPage->title(); // Nice shoes
  echo $itemPage->price(); // 99.99

Initialize Payment

Provide a paymentMethod and other data you need to handle the order (email, name, billing / shipping address etc.).

The payment is validated by the Order Page. Read more about validation.


$data = [
  'paymentMethod' => 'paypal',
  'email' => '',
  'name' => 'Chuck Norris',
try {
  $redirect = merx()->initializePayment($data);
} catch (Exception $ex) {
  echo $ex->getMessage();

Complete Payment

Depending on the payment method the customer is redirected directly or after the customer completed the payment on the payment provider’s external webpage (e.g. PayPal) to the success page.


try {
  $orderPage = merx()->completePayment();
  echo 'Payment completed.';
} catch (Exception $ex) {
  echo $ex->getMessage();