Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ib 3657 add invoice #10

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Action/Api/BaseApiAwareAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace PayHelper\Payum\Mollie\Action\Api;

use Mollie\Api\MollieApiClient;
use Payum\Core\Action\ActionInterface;
use Payum\Core\ApiAwareInterface;
use Payum\Core\ApiAwareTrait;
Expand All @@ -17,6 +18,6 @@ abstract class BaseApiAwareAction implements ActionInterface, GatewayAwareInterf

public function __construct()
{
$this->apiClass = \Mollie_API_Client::class;
$this->apiClass = MollieApiClient::class;
}
}
4 changes: 3 additions & 1 deletion Action/Api/CancelRecurringSubscriptionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace PayHelper\Payum\Mollie\Action\Api;

use Mollie\Api\Resources\Subscription;
use Mollie\Api\Types\SubscriptionStatus;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\Request\Cancel;
Expand All @@ -19,7 +21,7 @@ public function execute($request)

$model = ArrayObject::ensureArrayObject($request->getModel());

if (\Mollie_API_Object_Customer_Subscription::STATUS_CANCELLED ===
if (SubscriptionStatus::STATUS_CANCELED ===
$model['subscription']['status']) {
return;
}
Expand Down
11 changes: 6 additions & 5 deletions Action/Api/CreateCaptureAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@ class CreateCaptureAction extends BaseApiAwareAction
public function execute($request)
{
RequestNotSupportedException::assertSupports($this, $request);

$model = ArrayObject::ensureArrayObject($request->getModel());

$result = $this->api->payments->create([
'amount' => $model['amount'],
'amount' => [
'value' => sprintf('%.2f', $model['amount']),
'currency' => $model['currency'],
],
'method' => $model['method'],
'description' => $model['description'],
'redirectUrl' => $model['returnUrl'],
'webhookUrl' => $model['notifyUrl'],
'metadata' => $model['metadata'],
]);

$model->replace(['payment' => (array) $result]);

throw new HttpRedirect($result->links->paymentUrl);
throw new HttpRedirect($result->_links->checkout->href);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion Action/Api/CreateCustomerAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace PayHelper\Payum\Mollie\Action\Api;

use Mollie\Api\MollieApiClient;
use Payum\Core\Action\ActionInterface;
use Payum\Core\ApiAwareInterface;
use Payum\Core\ApiAwareTrait;
Expand All @@ -17,7 +18,7 @@ class CreateCustomerAction implements ActionInterface, ApiAwareInterface

public function __construct()
{
$this->apiClass = \Mollie_API_Client::class;
$this->apiClass = MollieApiClient::class;
}

/**
Expand Down
8 changes: 6 additions & 2 deletions Action/Api/CreateRecurringSubscriptionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace PayHelper\Payum\Mollie\Action\Api;

use Mollie\Api\MollieApiClient;
use Payum\Core\Action\ActionInterface;
use Payum\Core\ApiAwareInterface;
use Payum\Core\ApiAwareTrait;
Expand All @@ -17,7 +18,7 @@ class CreateRecurringSubscriptionAction implements ActionInterface, ApiAwareInte

public function __construct()
{
$this->apiClass = \Mollie_API_Client::class;
$this->apiClass = MollieApiClient::class;
}

/**
Expand All @@ -32,7 +33,10 @@ public function execute($request)
$model->validateNotEmpty(['interval', 'startDate', 'customer']);

$subscription = $this->api->customers_subscriptions->withParentId($model['customer']['id'])->create([
'amount' => $model['amount'],
'amount' => [
'value' => sprintf('%.2f', $model['amount']),
'currency' => $model['currency'],
],
'interval' => $model['interval'],
'description' => sprintf('Recurring subscription for customer %s', $model['customer']['id']),
'method' => $model['method'],
Expand Down
17 changes: 12 additions & 5 deletions Action/Api/CreateSepaOneOffPaymentAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

namespace PayHelper\Payum\Mollie\Action\Api;

use Mollie\Api\MollieApiClient;
use Mollie\Api\Types\MandateStatus;
use Mollie\Api\Types\PaymentMethod;
use Mollie\Api\Types\SequenceType;
use PayHelper\Payum\Mollie\Request\Api\CreateSepaOneOffPayment;
use Payum\Core\Action\ActionInterface;
use Payum\Core\ApiAwareInterface;
Expand All @@ -18,7 +22,7 @@ class CreateSepaOneOffPaymentAction implements ActionInterface, ApiAwareInterfac

public function __construct()
{
$this->apiClass = \Mollie_API_Client::class;
$this->apiClass = MollieApiClient::class;
}

/**
Expand All @@ -33,23 +37,26 @@ public function execute($request)
$model->validateNotEmpty(['sepaIban', 'sepaHolder', 'customer']);

$response = $this->api->customers_mandates->withParentId($model['customer']['id'])->create([
'method' => \Mollie_API_Object_Method::DIRECTDEBIT,
'method' => PaymentMethod::DIRECTDEBIT,
'consumerAccount' => $model['sepaIban']->get(),
'consumerName' => $model['sepaHolder']->get(),
]);

$mandate = ArrayObject::ensureArrayObject($response);

if (\Mollie_API_Object_Customer_Mandate::STATUS_VALID !== $mandate['status']) {
if (MandateStatus::STATUS_VALID !== $mandate['status']) {
throw new LogicException('Mandate is invalid.');
}

$model->replace(['mandate' => (array) $mandate]);

$payment = $this->api->payments->create([
'amount' => $model['amount'],
'amount' => [
'value' => sprintf('%.2f', $model['amount']),
'currency' => $model['currency'],
],
'description' => 'An on-demand payment (one-off)',
'recurringType' => \Mollie_API_Object_Payment::RECURRINGTYPE_RECURRING,
'recurringType' => SequenceType::SEQUENCETYPE_RECURRING,
'redirectUrl' => $model['returnUrl'],
'webhookUrl' => $model['notifyUrl'],
'customerId' => $model['customer']['id'],
Expand Down
5 changes: 3 additions & 2 deletions Action/CaptureAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace PayHelper\Payum\Mollie\Action;

use Mollie\Api\Types\PaymentMethod;
use PayHelper\Payum\Mollie\Constants;
use PayHelper\Payum\Mollie\Request\Api\CreateCustomer;
use PayHelper\Payum\Mollie\Request\Api\CreateSepaOneOffPayment;
Expand Down Expand Up @@ -90,15 +91,15 @@ public function execute($request)
}

switch ($method) {
case \Mollie_API_Object_Method::DIRECTDEBIT:
case PaymentMethod::DIRECTDEBIT:
$this->gateway->execute(new CreateSepaMandate($model));
$this->gateway->execute(new CreateRecurringSubscription($model));
break;
case Constants::METHOD_DIRECTDEBIT_ONEOFF:
$this->gateway->execute(new CreateCustomer($model));
$this->gateway->execute(new CreateSepaOneOffPayment($model));
break;
case \Mollie_API_Object_Method::CREDITCARD:
case PaymentMethod::CREDITCARD:
default:
$this->gateway->execute(new CreateCapture($model));
break;
Expand Down
30 changes: 17 additions & 13 deletions Action/StatusAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

namespace PayHelper\Payum\Mollie\Action;

use Mollie\Api\Types\PaymentStatus;
use Mollie\Api\Types\RefundStatus;
use Mollie\Api\Types\SettlementStatus;
use Mollie\Api\Types\SubscriptionStatus;
use Payum\Core\Action\ActionInterface;
use Payum\Core\Request\GetStatusInterface;
use Payum\Core\Bridge\Spl\ArrayObject;
Expand All @@ -24,23 +28,23 @@ public function execute($request)

if (isset($model['subscription'])) {
switch ($model['subscription']['status']) {
case \Mollie_API_Object_Customer_Subscription::STATUS_ACTIVE:
case SubscriptionStatus::STATUS_ACTIVE:
$request->markAuthorized();

break;
case \Mollie_API_Object_Customer_Subscription::STATUS_PENDING:
case SubscriptionStatus::STATUS_PENDING:
$request->markPending();

break;
case \Mollie_API_Object_Customer_Subscription::STATUS_CANCELLED:
case SubscriptionStatus::STATUS_CANCELED:
$request->markCanceled();

break;
case \Mollie_API_Object_Customer_Subscription::STATUS_COMPLETED:
case SubscriptionStatus::STATUS_COMPLETED:
$request->markCaptured();

break;
case \Mollie_API_Object_Customer_Subscription::STATUS_SUSPENDED:
case SubscriptionStatus::STATUS_SUSPENDED:
$request->markSuspended();

break;
Expand All @@ -60,35 +64,35 @@ public function execute($request)
}

switch ($model['payment']['status']) {
case \Mollie_API_Object_Payment::STATUS_OPEN:
case PaymentStatus::STATUS_OPEN:
$request->markNew();

break;
case \Mollie_API_Object_Payment::STATUS_PAID:
case PaymentStatus::STATUS_PAID:
$request->markCaptured();

break;
case \Mollie_API_Object_Payment::STATUS_CANCELLED:
case PaymentStatus::STATUS_CANCELED:
$request->markCanceled();

break;
case \Mollie_API_Object_Payment::STATUS_PENDING:
case PaymentStatus::STATUS_PENDING:
$request->markPending();

break;
case \Mollie_API_Object_Payment::STATUS_FAILED:
case PaymentStatus::STATUS_FAILED:
$request->markFailed();

break;
case \Mollie_API_Object_Payment::STATUS_PAIDOUT:
case SettlementStatus::STATUS_PAIDOUT:
$request->markPayedout();

break;
case \Mollie_API_Object_Payment::STATUS_EXPIRED:
case PaymentStatus::STATUS_EXPIRED:
$request->markExpired();

break;
case \Mollie_API_Object_Payment::STATUS_REFUNDED:
case RefundStatus::STATUS_REFUNDED:
$request->markRefunded();

break;
Expand Down
4 changes: 3 additions & 1 deletion MollieGatewayFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace PayHelper\Payum\Mollie;

use Mollie\Api\MollieApiClient;
use Mollie\Api\Resources\Refund;
use PayHelper\Payum\Mollie\Action\Api\CancelRecurringSubscriptionAction;
use PayHelper\Payum\Mollie\Action\Api\CreateCaptureAction;
use PayHelper\Payum\Mollie\Action\Api\CreateCustomerAction;
Expand Down Expand Up @@ -59,7 +61,7 @@ protected function populateConfig(ArrayObject $config)
$config['payum.api'] = function (ArrayObject $config) {
$config->validateNotEmpty($config['payum.required_options']);

$client = new \Mollie_API_Client();
$client = new MollieApiClient();
$client->setApiKey($config['apiKey']);

return $client;
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Installing the extension
Install this extension as a Composer dependency by requiring it in a `composer.json` file:

```bash
composer require payhelper/payum-mollie
composer require webbaard/payum-mollie
```

Register the Mollie Payum factory using `PayumBuilder`:
Expand Down
19 changes: 9 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
{
"name": "payhelper/payum-mollie",
"name": "webbaard/payum-mollie",
"type": "library",
"description": "The Payum extension. It provides Mollie payment integration.",
"description": "The Payum extension. It provides Mollie payment integration. used to be maintained by Rafał Muszyński but couldn't see any activity",
"keywords": ["payment", "payum", "mollie", "sepa", "directdebit", "creditcard"],
"homepage": "https://sourcefabric.org",
"license": "GPLv3",
"authors": [
{
"name": "Rafał Muszyński",
"email": "[email protected]"
"name": "Tim Huijzers",
"email": "[email protected]"
}
],
"require": {
"php": "^7.1",
"payum/core": "^1.3",
"mollie/mollie-api-php": "^1.9"
"php": "^7.2 || ^8.0",
"payum/core": "~1.5",
"mollie/mollie-api-php": "^2.44"
},
"require-dev": {
"payum/core": "^1.3@dev",
"php-http/guzzle6-adapter": "^1.0",
"phpspec/phpspec": "^4.0"
"php-http/guzzle6-adapter": "~1.1",
"phpspec/phpspec": "~7.5"
},
"config": {
"bin-dir": "bin"
Expand Down