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

Adding support for Gateway Mollie Connect #52

Closed
wants to merge 5 commits into from
Closed
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ composer require league/omnipay omnipay/mollie
The following gateways are provided by this package:

* Mollie
* Mollie_Connect

For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay)
repository.
Expand Down
161 changes: 161 additions & 0 deletions src/ConnectGateway.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<?php

namespace Omnipay\Mollie;

use Omnipay\Common\AbstractGateway;
use Omnipay\Common\Message\RequestInterface;
use Omnipay\Mollie\Message\Request\ConnectCompletePurchaseRequest;
use Omnipay\Mollie\Message\Request\ConnectCreateCustomerRequest;
use Omnipay\Mollie\Message\Request\ConnectFetchCustomerRequest;
use Omnipay\Mollie\Message\Request\ConnectFetchIssuersRequest;
use Omnipay\Mollie\Message\Request\ConnectFetchPaymentMethodsRequest;
use Omnipay\Mollie\Message\Request\ConnectFetchTransactionRequest;
use Omnipay\Mollie\Message\Request\ConnectPurchaseRequest;
use Omnipay\Mollie\Message\Request\ConnectRefundRequest;
use Omnipay\Mollie\Message\Request\ConnectUpdateCustomerRequest;

class ConnectGateway extends AbstractGateway
{
/**
* @return string
*/
public function getName()
{
return 'Mollie Connect';
}

/**
* @return array
*/
public function getDefaultParameters()
{
return array(
'apiKey' => ''
);
}

/**
* @return string
*/
public function getApiKey()
{
return $this->getParameter('apiKey');
}

/**
* @param string $value
* @return $this
*/
public function setApiKey($value)
{
return $this->setParameter('apiKey', $value);
}

/**
* @param array $parameters
* @return ConnectFetchIssuersRequest
*/
public function fetchIssuers(array $parameters = [])
{
/** @var ConnectFetchIssuersRequest $request */
$request = $this->createRequest(ConnectFetchIssuersRequest::class, $parameters);

return $request;
}

/**
* @param array $parameters
* @return ConnectFetchPaymentMethodsRequest
*/
public function fetchPaymentMethods(array $parameters = [])
{
/** @var ConnectFetchPaymentMethodsRequest $request */
$request = $this->createRequest(ConnectFetchPaymentMethodsRequest::class, $parameters);

return $request;
}

/**
* @param array $parameters
* @return ConnectFetchTransactionRequest
*/
public function fetchTransaction(array $parameters = [])
{
/** @var ConnectFetchTransactionRequest $request */
$request = $this->createRequest(ConnectFetchTransactionRequest::class, $parameters);

return $request;
}

/**
* @param array $parameters
* @return ConnectPurchaseRequest
*/
public function purchase(array $parameters = [])
{
/** @var ConnectPurchaseRequest $request */
$request = $this->createRequest(ConnectPurchaseRequest::class, $parameters);

return $request;
}

/**
* @param array $parameters
* @return CompletePurchaseRequest
*/
public function completePurchase(array $parameters = [])
{
/** @var ConnectCompletePurchaseRequest $request */
$request = $this->createRequest(ConnectCompletePurchaseRequest::class, $parameters);

return $request;
}

/**
* @param array $parameters
* @return ConnectRefundRequest
*/
public function refund(array $parameters = [])
{
/** @var ConnectRefundRequest $request */
$request = $this->createRequest(ConnectRefundRequest::class, $parameters);

return $request;
}

/**
* @param array $parameters
* @return ConnectCreateCustomerRequest
*/
public function createCustomer(array $parameters = [])
{
/** @var ConnectCreateCustomerRequest $request */
$request = $this->createRequest(ConnectCreateCustomerRequest::class, $parameters);

return $request;
}

/**
* @param array $parameters
* @return ConnectUpdateCustomerRequest
*/
public function updateCustomer(array $parameters = [])
{
/** @var ConnectUpdateCustomerRequest $request */
$request = $this->createRequest(ConnectUpdateCustomerRequest::class, $parameters);

return $request;
}

/**
* @param array $parameters
* @return ConnectFetchCustomerRequest
*/
public function fetchCustomer(array $parameters = [])
{
/** @var ConnectFetchCustomerRequest $request */
$request = $this->createRequest(ConnectFetchCustomerRequest::class, $parameters);

return $request;
}
}
17 changes: 17 additions & 0 deletions src/Message/Request/AbstractMollieRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ public function setApiKey($value)
return $this->setParameter('apiKey', $value);
}

/**
* @return string
*/
public function getProfileId()
{
return $this->getParameter('profileId');
}

/**
* @param string $value
* @return $this
*/
public function setProfileId($value)
{
return $this->setParameter('profileId', $value);
}

/**
* @param string $value
* @return $this
Expand Down
54 changes: 54 additions & 0 deletions src/Message/Request/ConnectCompletePurchaseRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Omnipay\Mollie\Message\Request;

use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Mollie\Message\Response\CompletePurchaseResponse;

/**
* Retrieve a single payment object by its payment token.
*
* @see https://docs.mollie.com/reference/v2/payments-api/get-payment
* @see https://docs.mollie.com/reference/v2/payments-api/get-payment#mollie-connect-oauth-parameters
*/
class ConnectCompletePurchaseRequest extends CompletePurchaseRequest
{
/**
* @return array
* @throws InvalidRequestException
*/
public function getData()
{
$this->validate('apiKey');

$data = [];
$data['id'] = $this->getTransactionReference();

if ($this->getTestMode()) {
$data['testmode'] = $this->getTestMode();
}

if (!isset($data['id'])) {
$data['id'] = $this->httpRequest->request->get('id');
}

if (empty($data['id'])) {
throw new InvalidRequestException("The transactionReference parameter is required");
}

return $data;
}

/**
* @param array $data
* @return CompletePurchaseResponse
*/
public function sendData($data)
{
$queryString = isset($data['testmode']) ? '?testmode=' . var_export($data['testmode'], true) : '';

$response = $this->sendRequest(self::GET, '/payments/' . $data['id'] . $queryString);

return $this->response = new CompletePurchaseResponse($this, $response);
}
}
51 changes: 51 additions & 0 deletions src/Message/Request/ConnectCreateCustomerRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Omnipay\Mollie\Message\Request;

use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Common\Message\AbstractRequest;
use Omnipay\Mollie\Message\Response\CreateCustomerResponse;

/**
* Creates a simple minimal representation of a customer in the Mollie API.
*
* @see https://docs.mollie.com/reference/v2/customers-api/create-customer
* @see https://docs.mollie.com/reference/v2/customers-api/create-customer#mollie-connect-oauth-parameters
*/
class ConnectCreateCustomerRequest extends CreateCustomerRequest
{
/**
* @return array
* @throws InvalidRequestException
*/
public function getData()
{
$this->validate('apiKey', 'description', 'email');

$data = [];
$data['name'] = $this->getDescription();
$data['email'] = $this->getEmail();
$data['locale'] = $this->getLocale();

if ($this->getMetadata()) {
$data['metadata'] = $this->getMetadata();
}

if ($this->getTestMode()) {
$data['testmode'] = $this->getTestMode();
}

return $data;
}

/**
* @param array $data
* @return CreateCustomerResponse
*/
public function sendData($data)
{
$response = $this->sendRequest(self::POST, '/customers', $data);

return $this->response = new CreateCustomerResponse($this, $response);
}
}
46 changes: 46 additions & 0 deletions src/Message/Request/ConnectFetchCustomerRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Omnipay\Mollie\Message\Request;

use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Common\Message\AbstractRequest;
use Omnipay\Mollie\Message\Response\FetchCustomerResponse;

/**
* Retrieve a single customer by its ID.
*
* @see https://docs.mollie.com/reference/v2/customers-api/get-customer
* @see https://docs.mollie.com/reference/v2/customers-api/get-customer#mollie-connect-oauth-parameters
*/
class ConnectFetchCustomerRequest extends FetchCustomerRequest
{
/**
* @return array
* @throws InvalidRequestException
*/
public function getData()
{
$this->validate('apiKey', 'customerReference');

$data = [];

if ($this->getTestMode()) {
$data['testmode'] = $this->getTestMode();
}

return $data;
}

/**
* @param array $data
* @return FetchCustomerResponse
*/
public function sendData($data)
{
$queryString = isset($data['testmode']) ? '?testmode=' . var_export($data['testmode'], true) : '';

$response = $this->sendRequest(self::GET, '/customers/' . $this->getCustomerReference() . $queryString);

return $this->response = new FetchCustomerResponse($this, $response);
}
}
Loading