wagnerwagner / merx

Merx is a plugin to create online shops with Kirby.
https://merx.wagnerwagner.de
102 stars 10 forks source link

initializePayment() returns memory error #26

Closed alexpi closed 3 years ago

alexpi commented 3 years ago

I am trying to integrate Stripe payments with Merx. I used the exact same code from the example at https://merx.wagnerwagner.de/cookbooks/checkout-with-stripe-s-payment-intents, but as soon as the initializePayment() function is called, the error "Allowed memory size of 134217728 bytes exhausted (tried to allocate 143360 bytes)", is returned. Am I missing something?

'pattern' => 'shop-api/submit',
'method' => 'POST',
'action' => function() {
  try {
    $data = [
      'paymentMethod' => 'credit-card-sca',
      'email' => 'chuck@example.com',
      'name' => 'Chuck Norris',
    ];

    $paymentIntentId = kirby()->session()->get('paymentIntentId');

    $data = array_merge($data, [
      'stripePaymentIntentId' => $paymentIntentId,
    ]);

    $redirect = merx()->initializePayment($data);

    return [
      'status' => 201,
      'redirect' => url($redirect),
    ];
  } catch (Kirby\Exception\Exception $ex) {
    return $ex->toArray();
  }
},
alexpi commented 3 years ago

The problem was indeed that PHP's memory size was not sufficient. Sorry!

alexpi commented 3 years ago

It worked once after increasing memory, but I am getting the error again. I am using the 8df5d40 commit.

tobiasfabian commented 3 years ago

Hey @alexpi,

I’m sorry, I can’t reproduce your issue.

Here are a few things you can try.

alexpi commented 3 years ago

It was my mistake after all. I was adding a shipping product, and instead of adding its id, to the cart, I was sending the whole shipping product file. Sorry for the trouble and thanks for your help!