Skip to content

Commit

Permalink
Add onboarding endpoint (#382)
Browse files Browse the repository at this point in the history
Big thanks to @LauLaman !
  • Loading branch information
LauLaman authored and sandervanhooft committed Apr 24, 2019
1 parent 6e69995 commit f3a7cdf
Show file tree
Hide file tree
Showing 30 changed files with 342 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/Endpoints/ChargebackEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Mollie\Api\Resources\Chargeback;
use Mollie\Api\Resources\ChargebackCollection;

class ChargebackEndpoint extends EndpointAbstract
class ChargebackEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "chargebacks";

Expand Down
18 changes: 18 additions & 0 deletions src/Endpoints/CollectionEndpointAbstract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Mollie\Api\Endpoints;

use Mollie\Api\Resources\BaseCollection;

abstract class CollectionEndpointAbstract extends EndpointAbstract
{
/**
* Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object.
*
* @param int $count
* @param object[] $_links
*
* @return BaseCollection
*/
abstract protected function getResourceCollectionObject($count, $_links);
}
2 changes: 1 addition & 1 deletion src/Endpoints/CustomerEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Mollie\Api\Resources\Customer;
use Mollie\Api\Resources\CustomerCollection;

class CustomerEndpoint extends EndpointAbstract
class CustomerEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "customers";

Expand Down
4 changes: 2 additions & 2 deletions src/Endpoints/CustomerPaymentsEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Mollie\Api\Resources\Payment;
use Mollie\Api\Resources\PaymentCollection;

class CustomerPaymentsEndpoint extends EndpointAbstract
class CustomerPaymentsEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "customers_payments";

Expand Down Expand Up @@ -94,4 +94,4 @@ public function listForId($customerId, $from = null, $limit = null, array $param

return parent::rest_list($from, $limit, $parameters);
}
}
}
10 changes: 0 additions & 10 deletions src/Endpoints/EndpointAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,6 @@ protected function rest_list($from = null, $limit = null, array $filters)
*/
abstract protected function getResourceObject();

/**
* Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object.
*
* @param int $count
* @param object[] $_links
*
* @return BaseCollection
*/
abstract protected function getResourceCollectionObject($count, $_links);

/**
* @param string $resourcePath
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Endpoints/InvoiceEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Mollie\Api\Resources\Invoice;
use Mollie\Api\Resources\InvoiceCollection;

class InvoiceEndpoint extends EndpointAbstract
class InvoiceEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "invoices";

Expand Down Expand Up @@ -75,4 +75,4 @@ public function all(array $parameters = [])
{
return $this->page( null, null, $parameters);
}
}
}
4 changes: 2 additions & 2 deletions src/Endpoints/MandateEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Mollie\Api\Resources\Mandate;
use Mollie\Api\Resources\MandateCollection;

class MandateEndpoint extends EndpointAbstract
class MandateEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "customers_mandates";

Expand Down Expand Up @@ -147,4 +147,4 @@ public function revokeForId($customerId, $mandateId, $data = [])

return parent::rest_delete($mandateId, $data);
}
}
}
2 changes: 1 addition & 1 deletion src/Endpoints/MethodEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Mollie\Api\Resources\MethodCollection;
use Mollie\Api\Resources\ResourceFactory;

class MethodEndpoint extends EndpointAbstract
class MethodEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "methods";

Expand Down
72 changes: 72 additions & 0 deletions src/Endpoints/OnboardingEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace Mollie\Api\Endpoints;

use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\BaseResource;
use Mollie\Api\Resources\Onboarding;
use Mollie\Api\Resources\ResourceFactory;

class OnboardingEndpoint extends EndpointAbstract
{
protected $resourcePath = "onboarding/me";

/**
* Get the object that is used by this API endpoint. Every API endpoint uses one type of object.
*
* @return BaseResource
*/
protected function getResourceObject()
{
return new Onboarding($this->client);
}

/**
* Retrieve the organization's onboarding status from Mollie.
*
* Will throw a ApiException if the resource cannot be found.
*
* @return Onboarding
* @throws ApiException
*/
public function get()
{
return $this->rest_read('', []);
}

/**
* Submit data that will be prefilled in the merchant’s onboarding.
* Please note that the data you submit will only be processed when the onboarding status is needs-data.
*
* Information that the merchant has entered in their dashboard will not be overwritten.
*
* Will throw a ApiException if the resource cannot be found.
*
* @return void
* @throws ApiException
*/
public function submit(array $parameters = [])
{

return $this->rest_create($parameters, []);
}

protected function rest_read($id, array $filters)
{
$result = $this->client->performHttpCall(
self::REST_READ,
$this->getResourcePath() . $this->buildQueryString($filters)
);

return ResourceFactory::createFromApiResult($result, $this->getResourceObject());
}

protected function rest_create(array $body, array $filters)
{
$this->client->performHttpCall(
self::REST_CREATE,
$this->getResourcePath() . $this->buildQueryString($filters),
$this->parseRequestBody($body)
);
}
}
2 changes: 1 addition & 1 deletion src/Endpoints/OrderEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Mollie\Api\Resources\Order;
use Mollie\Api\Resources\OrderCollection;

class OrderEndpoint extends EndpointAbstract
class OrderEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "orders";

Expand Down
2 changes: 1 addition & 1 deletion src/Endpoints/OrderLineEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Mollie\Api\Resources\OrderLineCollection;
use Mollie\Api\Resources\ResourceFactory;

class OrderLineEndpoint extends EndpointAbstract
class OrderLineEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "orders_lines";

Expand Down
2 changes: 1 addition & 1 deletion src/Endpoints/OrderPaymentEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Mollie\Api\Resources\Payment;
use Mollie\Api\Resources\PaymentCollection;

class OrderPaymentEndpoint extends EndpointAbstract
class OrderPaymentEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "orders_payments";

Expand Down
2 changes: 1 addition & 1 deletion src/Endpoints/OrderRefundEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Mollie\Api\Resources\Refund;
use Mollie\Api\Resources\RefundCollection;

class OrderRefundEndpoint extends EndpointAbstract
class OrderRefundEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "orders_refunds";

Expand Down
2 changes: 1 addition & 1 deletion src/Endpoints/OrganizationEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Mollie\Api\Resources\Organization;
use Mollie\Api\Resources\OrganizationCollection;

class OrganizationEndpoint extends EndpointAbstract
class OrganizationEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "organizations";

Expand Down
2 changes: 1 addition & 1 deletion src/Endpoints/PaymentCaptureEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Mollie\Api\Resources\CaptureCollection;
use Mollie\Api\Resources\Payment;

class PaymentCaptureEndpoint extends EndpointAbstract
class PaymentCaptureEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "payments_captures";

Expand Down
2 changes: 1 addition & 1 deletion src/Endpoints/PaymentChargebackEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Mollie\Api\Resources\ChargebackCollection;
use Mollie\Api\Resources\Payment;

class PaymentChargebackEndpoint extends EndpointAbstract
class PaymentChargebackEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "payments_chargebacks";

Expand Down
2 changes: 1 addition & 1 deletion src/Endpoints/PaymentEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Mollie\Api\Resources\Refund;
use Mollie\Api\Resources\ResourceFactory;

class PaymentEndpoint extends EndpointAbstract
class PaymentEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "payments";

Expand Down
2 changes: 1 addition & 1 deletion src/Endpoints/PaymentRefundEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Mollie\Api\Resources\Refund;
use Mollie\Api\Resources\RefundCollection;

class PaymentRefundEndpoint extends EndpointAbstract
class PaymentRefundEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "payments_refunds";

Expand Down
2 changes: 1 addition & 1 deletion src/Endpoints/PermissionEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Mollie\Api\Resources\Permission;
use Mollie\Api\Resources\PermissionCollection;

class PermissionEndpoint extends EndpointAbstract
class PermissionEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "permissions";

Expand Down
4 changes: 2 additions & 2 deletions src/Endpoints/ProfileEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Mollie\Api\Resources\Profile;
use Mollie\Api\Resources\ProfileCollection;

class ProfileEndpoint extends EndpointAbstract
class ProfileEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "profiles";
protected $resourceClass = Profile::class;
Expand Down Expand Up @@ -117,4 +117,4 @@ public function page($from = null, $limit = null, array $parameters = [])
}


}
}
2 changes: 1 addition & 1 deletion src/Endpoints/ProfileMethodEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Mollie\Api\Resources\Profile;
use Mollie\Api\Resources\ResourceFactory;

class ProfileMethodEndpoint extends EndpointAbstract
class ProfileMethodEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "profiles_methods";

Expand Down
2 changes: 1 addition & 1 deletion src/Endpoints/RefundEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Mollie\Api\Resources\Refund;
use Mollie\Api\Resources\RefundCollection;

class RefundEndpoint extends EndpointAbstract
class RefundEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "refunds";

Expand Down
4 changes: 2 additions & 2 deletions src/Endpoints/SettlementsEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Mollie\Api\Resources\Settlement;
use Mollie\Api\Resources\SettlementCollection;

class SettlementsEndpoint extends EndpointAbstract
class SettlementsEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "settlements";

Expand Down Expand Up @@ -84,4 +84,4 @@ public function page($from = null, $limit = null, array $parameters = [])
{
return $this->rest_list($from, $limit, $parameters);
}
}
}
2 changes: 1 addition & 1 deletion src/Endpoints/ShipmentEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Mollie\Api\Resources\Shipment;
use Mollie\Api\Resources\ShipmentCollection;

class ShipmentEndpoint extends EndpointAbstract
class ShipmentEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "orders_shipments";

Expand Down
4 changes: 2 additions & 2 deletions src/Endpoints/SubscriptionEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Mollie\Api\Resources\Subscription;
use Mollie\Api\Resources\SubscriptionCollection;

class SubscriptionEndpoint extends EndpointAbstract
class SubscriptionEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "customers_subscriptions";

Expand Down Expand Up @@ -94,4 +94,4 @@ public function cancelFor(Customer $customer, $subscriptionId, array $data = [])

return parent::rest_delete($subscriptionId, $data);
}
}
}
10 changes: 9 additions & 1 deletion src/MollieApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Mollie\Api\Endpoints\InvoiceEndpoint;
use Mollie\Api\Endpoints\MandateEndpoint;
use Mollie\Api\Endpoints\MethodEndpoint;
use Mollie\Api\Endpoints\OnboardingEndpoint;
use Mollie\Api\Endpoints\OrderEndpoint;
use Mollie\Api\Endpoints\OrderLineEndpoint;
use Mollie\Api\Endpoints\OrderPaymentEndpoint;
Expand Down Expand Up @@ -156,6 +157,13 @@ class MollieApiClient
*/
public $invoices;

/**
* RESTful Onboarding resource.
*
* @var OnboardingEndpoint
*/
public $onboarding;

/**
* RESTful Order resource.
*
Expand Down Expand Up @@ -242,7 +250,6 @@ class MollieApiClient
* @var array
*/
protected $versionStrings = [];

/**
* @var int
*/
Expand Down Expand Up @@ -285,6 +292,7 @@ public function initializeEndpoints()
$this->invoices = new InvoiceEndpoint($this);
$this->permissions = new PermissionEndpoint($this);
$this->profiles = new ProfileEndpoint($this);
$this->onboarding = new OnboardingEndpoint($this);
$this->organizations = new OrganizationEndpoint($this);
$this->orders = new OrderEndpoint($this);
$this->orderLines = new OrderLineEndpoint($this);
Expand Down
Loading

0 comments on commit f3a7cdf

Please sign in to comment.