<?php
class PerchShopGateway_mollie extends PerchShopGateway_default
{
On the bottom of default.class.php it does overwrite, but when in the seperate file it won't.
Also Perch returns the orders as failed, even though the orders are successful (On my Mollie account they show as successful).
I suppose this is because I have to overwrite some methods from the default gateway class, right?
<?php
require($_SERVER['DOCUMENT_ROOT'].'/vendor/autoload.php');
use Omnipay\Mollie\Gateway;
Gateway class Mollie root/perch/addons/apps/mollie/PerchShopGateway_mollie.class.php:
<?php
class PerchShopGateway_mollie extends PerchShopGateway_default
{
protected $slug = 'mollie';
public $omnipay_name = 'Mollie';
#######
Now my final and last problem (I hope) is that Perch doesn't redirect me to the cancel_url when cancelling a payment, and that Perch is not returning a payment as successful when Mollie says it is.
But I think Perch is not seeing 'webhookUrl' as a valid URL. Just like returnUrl has to be return_url. How could I fix this? (Or am I even looking in the right direction)
I was looking in the database and found all the orders. They all have the status 'created'. When changing an order to 'paid' in the database, it is showing in the Orders app, with all the information that I need. So, my only problem now is that the status is not sent back to Perch.
require_once 'Mollie/API/Autoloader.php';
$mollie = new Mollie_API_Client;
$mollie->setApiKey('test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM');
$payment = $mollie->payments->get($_POST["id"]);
/*
* The order ID saved in the payment can be used to load the order and update it's
* status
*/
$order_id = $payment->metadata->order_id;
if ($payment->isPaid())
{
/*
* At this point you'd probably want to start the process of delivering the product
* to the customer.
*/
}
elseif (! $payment->isOpen())
{
/*
* The payment isn't paid and isn't open anymore. We can assume it was aborted.
*/
}
Mollie uses a webhook to check and send back the status of the order. In this code they use get($_POST["id"]); to get the id of the order. In the database I see that this id also gets sent to Perch, as orderGatewayRef().
I found CompletePurchaseRequestTest.php in the omnipay mollie folder, maybe you know if it is of any help:
(The 'tr_Qzin4iTWrU' code is the order id, which I can see for every order in the database (orderGatewayRef())
<?php
namespace Omnipay\Mollie\Message;
use Omnipay\Tests\TestCase;
class CompletePurchaseRequestTest extends TestCase
{
/**
* @var \Omnipay\Mollie\Message\CompletePurchaseRequest
*/
protected $request;
public function setUp()
{
$this->request = new CompletePurchaseRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(array(
'apiKey' => 'mykey',
));
$this->getHttpRequest()->request->replace(array(
'id' => 'tr_Qzin4iTWrU',
));
}
/**
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
* @expectedExceptionMessage The transactionReference parameter is required
*/
public function testGetDataWithoutIDParameter()
{
$this->getHttpRequest()->request->remove('id');
$data = $this->request->getData();
$this->assertEmpty($data);
}
public function testGetData()
{
$data = $this->request->getData();
$this->assertSame("tr_Qzin4iTWrU", $data['id']);
$this->assertCount(1, $data);
}
public function testSendSuccess()
{
$this->setMockHttpResponse('CompletePurchaseSuccess.txt');
$response = $this->request->send();
$this->assertInstanceOf('Omnipay\Mollie\Message\CompletePurchaseResponse', $response);
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isOpen());
$this->assertTrue($response->isPaid());
$this->assertFalse($response->isRedirect());
$this->assertSame('tr_Qzin4iTWrU', $response->getTransactionReference());
}
public function testSendExpired()
{
$this->setMockHttpResponse('CompletePurchaseExpired.txt');
$response = $this->request->send();
$this->assertInstanceOf('Omnipay\Mollie\Message\CompletePurchaseResponse', $response);
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isPaid());
$this->assertTrue($response->isExpired());
$this->assertFalse($response->isRedirect());
$this->assertSame('tr_Qzin4iTWrU', $response->getTransactionReference());
}
public function testSendFailure()
{
$this->setMockHttpResponse('PurchaseFailure.txt');
$response = $this->request->send();
$this->assertInstanceOf('Omnipay\Mollie\Message\CompletePurchaseResponse', $response);
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertSame("The issuer is invalid", $response->getMessage());
}
}
No I did not. I am now looking at the worldpay and sagepay action_payment_callback() functions, but I am not sure how to change them so it works with Mollie.
Yes, I tried multiple times. When I add:
On the bottom of default.class.php it does overwrite, but when in the seperate file it won't.
Also Perch returns the orders as failed, even though the orders are successful (On my Mollie account they show as successful). I suppose this is because I have to overwrite some methods from the default gateway class, right?
That sounds like an issue with how you're loading the classes. I don't think it's a Perch issue.
Do you think that is also the reason Perch doesn't see the payment as successful?
I think you need to make sure PHP is using your class before we can even speculate as to that.
Okay, I am really stuck at this point.
In
/perch_shop/lib/
there is a 'vendor' map with some gateways. When installing omnipay mollie via composer, I also got a 'vendor' map in the root.From which vendor folder do I need to call the
autoload.php
?I am now using:
When I include the autoload from
/perch_shop/lib
I get an error, so I don't think I have to use that one:You don't need to mess with anything in
/perch_shop/lib/
If you've added your own vendor folder, make sure you include its autoloader.
My gateway class is now overwriting the default gateway class!
Autoloader
root/vendor/autoload.php
:Runtime
root/perch/addons/apps/mollie/runtime.php
:Gateway class Mollie
root/perch/addons/apps/mollie/PerchShopGateway_mollie.class.php
:Now my final and last problem (I hope) is that Perch doesn't redirect me to the cancel_url when cancelling a payment, and that Perch is not returning a payment as successful when Mollie says it is.
Mollie is using a webhook URL to check the status of a payment. For that to work I need to add:
But I think Perch is not seeing 'webhookUrl' as a valid URL. Just like returnUrl has to be return_url. How could I fix this? (Or am I even looking in the right direction)
I was looking in the database and found all the orders. They all have the status 'created'. When changing an order to 'paid' in the database, it is showing in the Orders app, with all the information that I need. So, my only problem now is that the status is not sent back to Perch.
Mollie docs: https://www.mollie.com/nl/docs/webhook
Mollie uses a webhook to check and send back the status of the order. In this code they use
get($_POST["id"]);
to get the id of the order. In the database I see that this id also gets sent to Perch, asorderGatewayRef()
.The webhook is requested with a webhookUrl like this: (https://www.mollie.com/nl/docs/reference/payments/create)
Could you please help me with this last piece of the puzzle?
I found
CompletePurchaseRequestTest.php
in the omnipay mollie folder, maybe you know if it is of any help: (The 'tr_Qzin4iTWrU' code is the order id, which I can see for every order in the database (orderGatewayRef())What are you expecting me to do here? I'm not sure how I can help you.
I want to know how to change the status from 'created' to 'paid'
Have you implemented
action_payment_callback()
in your gateway?No I did not. I am now looking at the worldpay and sagepay
action_payment_callback()
functions, but I am not sure how to change them so it works with Mollie.