Get shop info in Mollie API
Hello,
I'm not sure if I am doing it right because this is very new to me, but I am trying to use Mollie as a payment gateway to my shop.
My checkout.php:
<?php
// Show the cart with a non-interactive template
perch_shop_cart([
'template'=>'cart/cart_static.html'
]);
// Show the order addresses
perch_shop_order_addresses();
// Display the form with the T&Cs checkbox
// perch_shop_form('checkout/confirm.html');
?>
<?php
perch_shop_payment_form('stripe');
?>
My payment form:
<perch:form id="confirm" app="perch_shop" class="order-confirm" action="/shop/test">
<perch:input type="submit" value="Go" />
</perch:form>
Test.php (Page from the action of the form, where I call Mollie):
<?php
require_once('C:\xampp\htdocs\kevcel\vendor\Mollie\API\Autoloader.php');
$mollie = new Mollie_API_Client;
$mollie->setApiKey('test_a6xxfh7Was8KHhrRv44J7Gpjd6wqyG');
try
{
$payment = $mollie->payments->create(
array(
'amount' => '400.00',
'description' => 'My first payment',
'redirectUrl' => 'https://www.kevcel.test/shop/result.php',
'webhookUrl' => 'https://www.kevcel.test/shop/test-webhook.php',
'metadata' => array(
'order_id' => '12345'
)
)
);
/*
* Send the customer off to complete the payment.
* This request should always be a GET, thus we enforce 303 http response code
*/
header("Location: " . $payment->getPaymentUrl(), true, 303);
exit;
}
catch (Mollie_API_Exception $e)
{
echo "API call failed: " . htmlspecialchars($e->getMessage());
echo " on field " . htmlspecialchars($e->getField());
}
?>
So my question is, how do I get the order_id, amount etc. etc. in Mollie? Now I have put an amount etc. by myself, but it should get it from the perch order.
I hope someone can help me, thanks in advance.
Mike
Have you created a gateway adapter class?
No, I don't think so. How would I do that?
Is there any documentation on that subject? I can't seem to find anything.
You need to declare a gateway class, and make it available in your autoloader. You'll also need to include the Omnipay Mollie implementation.
https://omnipay.thephpleague.com/gateways/mollie/
You can then overwrite any of the methods defined in
PerchShopGateway_default
to customise the payment handling for Mollie.Okay, so I have created PerchShopGateway_mollie in /perch/addons/apps/perch_shop/lib/gateways
PerchShopGateway_mollie.class.php:
I also installed the Omnipay Mollie via composer.
How do I make the mollie gateway class available in my autoloader?
Autoloader.php (Mollie/API/Autoloader.php):
Thanks
Don't put your code there - it'll get replaced when you upgrade. Put it in somewhere like
/perch/addons/apps/hendricks_mollie
Then create
/perch/addons/apps/hendricks_mollie/runtime.php
and put your autoloader in there (or heck, just include the gateway file).Add
hendricks_mollie
to yourapps.php
file.I created
/perch/addons/apps/hendriks_mollie
in which I putruntime.php
andPerchShopGateway_mollie.class.php
.runtime.php:
PerchShopGateway_mollie.class.php:
perch/config/apps.php
:Am I on the right track now? Thank you for the help so far.
What problem are you now having?
Well, my test.php still looks like this:
What do I change there? This is my first time doing anything like this.
Do I change
require_once('C:\xampp\htdocs\kevcel\vendor\Mollie\API\Autoloader.php');
torequire_once('C:\xampp\htdocs\kevcel\perch\addons\apps\hendriks_mollie\runtime.php');
? And then edit the PerchShopGateway_default into PerchShopGateway_mollieDo I also change the
shop.php
?You'd then use your new gateway adapter with the checkout function:
On checkout.php I now get:
I copied my
Autoloader.php
inruntime.php
, but that was the Autoloader from my manual Mollie install, before installing the omnipay Mollie. So now I copied Gateway.php found inside/perch/addons/apps/perch_shop/lib/vendor/mollie/src/Gateway.php
inruntime.php
.Then I get the next error:
runtime.php
withAutoloader.php
from first install:runtime.php
withGateway.php
from omnipay mollie:I thought it was getting a bit of a mess at this point, so I decided to delete everything and start from scratch.
/perch/addons/apps/mollie_ideal
in which I createPerchShopGateway_mollie.class.php
andruntime.php
PerchShopGateway_mollie.class.php:
runtime.php (Took code from C:/xampp/htdocs/kevcel/vendor/omnipay/mollie/src/Gateway.php):
apps.php
checkout.php:
stripe_payment_form.html:
On
checkout.php
I now get this error:It looks like your autoloader isn't configured correctly.
Do you think that I have the right code in
runtime.php
? As said I took the code from:C:/xampp/htdocs/kevcel/vendor/omnipay/mollie/src/Gateway.php.
You said:
Then create /perch/addons/apps/hendricks_mollie/runtime.php and put your autoloader in there (or heck, just include the gateway file).
Which file do you mean by 'autoloader'?
Okay, so in my runtime.php I have included
C:/xampp/htdocs/kevcel/vendor/autoload.php
So now my page after checkout looks like this:
The page now returns:
I think I am almost there! So now it is only a matter of overwriting the methods from
PerchShopGateway_default.class.php
, am I right?Those undefined indexes was because of my
shop.php
file not being setup correctly.Fixed it:
YESSSS! I got Mollie working! Thank you for all the help, Drew.
The only problem that I am having right now, is that when I copy a public function from default.class.php to mollie.class.php it is not overwriting? It is still grabbing the function from default.class.php.
Example:
PerchShopGateway_default.class.php
PerchShopGateway_mollie.class.php
It is still returning 'Order' as description, and not 'Test Description'.
Are you sure?