Skip to content

Commit

Permalink
Merge pull request #725 from sandervanhooft/add_paymentlinks_patch_an…
Browse files Browse the repository at this point in the history
…d_delete

Add new PaymentLinks endpoints
  • Loading branch information
sandervanhooft authored Jun 24, 2024
2 parents 5c29df8 + 430034f commit 531d50d
Show file tree
Hide file tree
Showing 6 changed files with 722 additions and 4 deletions.
268 changes: 267 additions & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,270 @@ parameters:
ignoreErrors:
-
message: "#^Variable \\$mollie might not be defined\\.$#"
path: examples/*
count: 1
path: examples/captures/create-capture.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/captures/get-capture.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/captures/list-captures.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/client-links/create-client-link.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/customers/create-customer-first-payment.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/customers/create-customer-payment.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/customers/create-customer-recurring-payment.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/customers/create-customer.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/customers/delete-customer.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/customers/list-customer-payments.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/customers/update-customer.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/invoices/list-invoices.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/mandates/create-mandate.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/mandates/list-mandates.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/mandates/revoke-mandate.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 2
path: examples/orders/cancel-order-lines.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/orders/cancel-order.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/orders/create-order.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/orders/list-methods.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/orders/list-orders.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/orders/refund-order-completely.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/orders/refund-order-partially.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/orders/update-order-line.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/orders/update-order-lines-multiple.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/orders/update-order.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/orders/webhook.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 2
path: examples/pagination/backwards.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 2
path: examples/pagination/basic_usage.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/payment-links/create-payment-link.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/payment-links/list-payment-links.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/payments/create-capturable-payment.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 2
path: examples/payments/create-ideal-payment.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 2
path: examples/payments/create-payment-oauth.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/payments/create-payment.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/payments/list-methods.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/payments/list-payments.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/payments/refund-payment.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/payments/return.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/payments/update-payment.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/payments/webhook.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/profiles/create-profile.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/profiles/delete-profile.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/profiles/list-profiles.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/profiles/update-profile.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/settlements/list-settlements.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/shipments/create-shipment-all.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/shipments/create-shipment-partial.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/shipments/get-shipment.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/shipments/list-shipments.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/shipments/update-shipment.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/subscriptions/cancel-subscription.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/subscriptions/create-subscription.php

-
message: "#^Variable \\$mollie might not be defined\\.$#"
count: 1
path: examples/subscriptions/update-subscription.php

-
message: "#^Result of method Mollie\\\\Api\\\\Endpoints\\\\PaymentLinkEndpoint\\:\\:delete\\(\\) \\(void\\) is used\\.$#"
count: 1
path: tests/Mollie/API/Endpoints/PaymentLinkEndpointTest.php
8 changes: 7 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="./vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" convertDeprecationsToExceptions="true">
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
colors="true"
bootstrap="./vendor/autoload.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
convertDeprecationsToExceptions="true"
>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src/</directory>
Expand Down
35 changes: 34 additions & 1 deletion src/Endpoints/PaymentLinkEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Payment;
use Mollie\Api\Resources\PaymentLink;
use Mollie\Api\Resources\PaymentLinkCollection;

Expand All @@ -17,6 +16,40 @@ class PaymentLinkEndpoint extends CollectionEndpointAbstract
*/
public const RESOURCE_ID_PREFIX = 'pl_';

/**
* Update a Payment Link.
*
* @param string $paymentLinkId
* @param array $data
* @return PaymentLink
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function update(string $paymentLinkId, array $data)
{
if (empty($paymentLinkId) || strpos($paymentLinkId, self::RESOURCE_ID_PREFIX) !== 0) {
throw new ApiException("Invalid payment ID: '{$paymentLinkId}'. A Payment Link ID should start with '" . self::RESOURCE_ID_PREFIX . "'.");
}

return $this->rest_update($paymentLinkId, $data);
}

/**
* Delete a Payment Link.
*
* @param string $paymentLinkId
* @param array $data
* @return void
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function delete(string $paymentLinkId, array $data = [])
{
if (empty($paymentLinkId) || strpos($paymentLinkId, self::RESOURCE_ID_PREFIX) !== 0) {
throw new ApiException("Invalid payment ID: '{$paymentLinkId}'. A Payment Link ID should start with '" . self::RESOURCE_ID_PREFIX . "'.");
}

$this->rest_delete($paymentLinkId, $data);
}

/**
* @return PaymentLink
*/
Expand Down
59 changes: 59 additions & 0 deletions src/Resources/PaymentLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,63 @@ public function getCheckoutUrl()

return $this->_links->paymentLink->href;
}

/**
* Persist the current local Payment Link state to the Mollie API.
*
* @return mixed|\Mollie\Api\Resources\BaseResource
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function update()
{
$body = $this->withPresetOptions([
'description' => $this->description,
'archived' => $this->archived,
]);

$result = $this->client->paymentLinks->update($this->id, $body);

return ResourceFactory::createFromApiResult($result, new PaymentLink($this->client));
}

/**
* Archive this Payment Link.
*
* @return \Mollie\Api\Resources\PaymentLink
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function archive()
{
$data = $this->withPresetOptions([
'archived' => true,
]);

return $this->client->paymentLinks->update($this->id, $data);
}

/**
* When accessed by oAuth we want to pass the testmode by default
*
* @return array
*/
private function getPresetOptions()
{
$options = [];
if ($this->client->usesOAuth()) {
$options["testmode"] = $this->mode === "test";
}

return $options;
}

/**
* Apply the preset options.
*
* @param array $options
* @return array
*/
private function withPresetOptions(array $options)
{
return array_merge($this->getPresetOptions(), $options);
}
}
Loading

0 comments on commit 531d50d

Please sign in to comment.