Merx – Plugin to create online shops with Kirby 3

, ,

Hello @tobiasfabian

I’m hoping to use your plugin. I’ve managed to get it working apart from the final completion of payment through PayPal. In my checkout.php controller, I have the following.

<?PHP
     if (merx()->cart()->isEmpty()) {
      go('/');
     }
     if (kirby()->request()->method() === 'POST') {
      try {
      $data = $_POST;
      $redirect = merx()->initializePayment($data);
      go($redirect);
     } catch (Exception $ex) {
      echo $ex->getMessage();
      dump($ex->getDetails());
     }
    }

and my config is:

    <?php

    use Kirby\Exception\Exception;

    return [
      'debug' => true,
      'ww.merx.production' => false,
      'ww.merx.currency' => 'GBP',
      'ww.merx.currencySymbol' => '£',
      'ww.merx.gateways' => [
        'paypal' => [
          'ww.merx.paypal.sandbox.clientID' => '',
          'ww.merx.paypal.sandbox.secret' => ''
        ],
        'credit-card' => [
          'ww.merx.stripe.live.publishable_key' => 'pk_test_',
          'ww.merx.stripe.live.publishable_key' => 'sk_test_'
        ]
      ],
      'routes' => [
        [
          'pattern' => 'add',
          'method' => 'post|get',
          'action'  => function () {
            $id = get('id');
            $quantity = get('quantity');
            try {
              cart()->add([
                'id' => $id,
                'quantity' => $quantity,
              ]);
              go('/');
            } catch (Exception $ex) {
              return $ex->getMessage();
            }
          },
        ],
        [
          'pattern' => 'remove',
          'method' => 'post|get',
          'action'  => function () {
            $id = get('id');
            try {
              cart()->remove($id);
              go('/checkout');
            } catch (Exception $ex) {
              return $ex->getMessage();
            }
          },
        ],
      ],
      'hooks' => [
        'ww.merx.cart' => function ($cart) {
          if ($cart->count() > 0) {
            $cart->remove('shipping');
            if ($cart->getSum() < 2) {
              $cart->add([
                'id' => 'shipping',
              ]);
            }
          }
        }
      ],
    ];

I expected the go($redirect); to send to PayPal but instead, it loads the order.php of the order. Is there something / a setup step I’m missing?

Open question to all!