Initial commit
This commit is contained in:
commit
2b9e58beee
822 files changed
+62544
No files matched your search
+69
@@ -0,0 +1,69 @@
|
||||
# Create a Capturable Payment
|
||||
|
||||
How to create a payment that can be captured manually with the Mollie API.
|
||||
|
||||
## The Code
|
||||
|
||||
```php
|
||||
use Mollie\Api\Http\Data\Money;
|
||||
use Mollie\Api\Http\Requests\CreatePaymentRequest;
|
||||
use Mollie\Api\Types\PaymentMethod;
|
||||
use Mollie\Api\Types\PaymentStatus;
|
||||
|
||||
try {
|
||||
// Generate a unique order ID
|
||||
$orderId = time();
|
||||
|
||||
// Create the payment
|
||||
$payment = $mollie->send(
|
||||
new CreatePaymentRequest(
|
||||
description: "Order #{$orderId}",
|
||||
amount: Money::euro('10.00'), // Using convenience method
|
||||
redirectUrl: "https://example.com/return.php?order_id={$orderId}",
|
||||
cancelUrl: "https://example.com/cancel.php",
|
||||
webhookUrl: "https://example.com/webhook.php",
|
||||
metadata: ['order_id' => $orderId],
|
||||
method: PaymentMethod::Creditcard,
|
||||
captureMode: 'manual'
|
||||
)
|
||||
);
|
||||
|
||||
// PaymentStatus case for known values, raw string for anything newer.
|
||||
// Store the string: an enum case cannot be written to the database and
|
||||
// interpolating one throws.
|
||||
$status = $payment->status instanceof PaymentStatus
|
||||
? $payment->status->value
|
||||
: $payment->status;
|
||||
|
||||
// Store the order in the database
|
||||
database_write($orderId, $status);
|
||||
|
||||
// Redirect to checkout
|
||||
header('Location: ' . $payment->getCheckoutUrl(), true, 303);
|
||||
} catch (\Mollie\Api\Exceptions\ApiException $e) {
|
||||
echo 'API call failed: ' . htmlspecialchars($e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
## The Response
|
||||
|
||||
```php
|
||||
$payment->id; // "tr_7UhSN1zuXS"
|
||||
$payment->status; // PaymentStatus::Open, or the raw string for an unknown value
|
||||
$payment->amount->currency; // "EUR"
|
||||
$payment->amount->value; // "10.00"
|
||||
$payment->description; // "Order #1234"
|
||||
$payment->metadata->order_id; // "1234"
|
||||
$payment->method; // PaymentMethod::Creditcard, a raw string, or null
|
||||
$payment->captureMode; // "manual" (or null)
|
||||
$payment->getCheckoutUrl(); // "https://www.mollie.com/checkout/select-method/7UhSN1zuXS"
|
||||
```
|
||||
|
||||
## Additional Notes
|
||||
|
||||
- `status` is `PaymentStatus|string` and `method` is `PaymentMethod|string|null`; the string side keeps values a newer API returns from breaking your integration
|
||||
- Manual capturing is currently only supported for credit card payments, Billie, Riverty, and Klarna
|
||||
- For Klarna payments, submitting more data like order lines and addresses is required
|
||||
- After the payment is authorized, you'll need to capture it manually to actually charge the customer
|
||||
- The payment will remain in the 'authorized' status until you either capture or cancel it
|
||||
- Make sure to implement the webhook handler to process payment status updates
|
||||
@@ -0,0 +1,54 @@
|
||||
# Create a Payment Capture
|
||||
|
||||
How to capture a payment that was created with manual capture using the Mollie API.
|
||||
|
||||
## The Code
|
||||
|
||||
```php
|
||||
use Mollie\Api\Http\Data\Money;
|
||||
use Mollie\Api\Resources\Capture;
|
||||
use Mollie\Api\Http\Requests\CreatePaymentCaptureRequest;
|
||||
|
||||
try {
|
||||
// Create a capture for the payment
|
||||
/** @var Capture */
|
||||
$capture = $mollie->send(
|
||||
new CreatePaymentCaptureRequest(
|
||||
paymentId: 'tr_WDqYK6vllg',
|
||||
description: 'Order #12345',
|
||||
amount: Money::euro('5.00')
|
||||
)
|
||||
);
|
||||
|
||||
echo "New capture created: {$capture->id}\n";
|
||||
} catch (\Mollie\Api\Exceptions\ApiException $e) {
|
||||
echo "API call failed: " . htmlspecialchars($e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
## The Response
|
||||
|
||||
```php
|
||||
$capture->id; // "cpt_4qqhO89gsT"
|
||||
$capture->paymentId; // "tr_WDqYK6vllg"
|
||||
$capture->amount; // Money, or null when the API omits it
|
||||
$capture->amount?->currency; // "EUR"
|
||||
$capture->amount?->value; // "5.00"
|
||||
$capture->description; // "Order #12345" (or null)
|
||||
$capture->status; // "pending", "succeeded", "failed" (or null)
|
||||
$capture->createdAt; // "2024-02-24T12:13:14+00:00" (or null)
|
||||
```
|
||||
|
||||
`Capture::$amount` is nullable per the API contract, so guard it (or use `?->`)
|
||||
before reading `currency` or `value`. `status` is a plain nullable string here,
|
||||
not a backed enum.
|
||||
|
||||
## Additional Notes
|
||||
|
||||
- The payment must have been created with `captureMode: 'manual'`
|
||||
- The capture amount can be equal to or lower than the payment amount
|
||||
- You can create multiple partial captures for a single payment
|
||||
- The capture will be processed asynchronously
|
||||
- The payment status will change to `paid` once the capture is successful
|
||||
- Make sure to handle the webhook to process capture status updates
|
||||
- Captures are only available for certain payment methods (e.g., credit cards)
|
||||
@@ -0,0 +1,65 @@
|
||||
# Create an iDEAL Payment
|
||||
|
||||
How to prepare a new iDEAL payment with the Mollie API.
|
||||
|
||||
## The Code
|
||||
|
||||
```php
|
||||
use Mollie\Api\Http\Data\Money;
|
||||
use Mollie\Api\Http\Requests\CreatePaymentRequest;
|
||||
use Mollie\Api\Types\PaymentMethod;
|
||||
use Mollie\Api\Types\PaymentStatus;
|
||||
|
||||
try {
|
||||
// Generate a unique order ID
|
||||
$orderId = time();
|
||||
|
||||
// Create the payment
|
||||
$payment = $mollie->send(
|
||||
new CreatePaymentRequest(
|
||||
description: "Order #{$orderId}",
|
||||
amount: Money::euro('27.50'), // Using convenience method
|
||||
redirectUrl: "https://example.com/return.php?order_id={$orderId}",
|
||||
cancelUrl: "https://example.com/cancel.php",
|
||||
webhookUrl: "https://example.com/webhook.php",
|
||||
metadata: ['order_id' => $orderId],
|
||||
method: PaymentMethod::Ideal
|
||||
)
|
||||
);
|
||||
|
||||
// PaymentStatus case for known values, raw string for anything newer.
|
||||
// Store the string: an enum case cannot be written to the database and
|
||||
// interpolating one throws.
|
||||
$status = $payment->status instanceof PaymentStatus
|
||||
? $payment->status->value
|
||||
: $payment->status;
|
||||
|
||||
// Store the order in the database
|
||||
database_write($orderId, $status);
|
||||
|
||||
// Redirect to checkout
|
||||
header('Location: ' . $payment->getCheckoutUrl(), true, 303);
|
||||
} catch (\Mollie\Api\Exceptions\ApiException $e) {
|
||||
echo 'API call failed: ' . htmlspecialchars($e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
## The Response
|
||||
|
||||
```php
|
||||
$payment->id; // "tr_7UhSN1zuXS"
|
||||
$payment->status; // PaymentStatus::Open, or the raw string for an unknown value
|
||||
$payment->amount->currency; // "EUR"
|
||||
$payment->amount->value; // "27.50"
|
||||
$payment->description; // "Order #1234"
|
||||
$payment->metadata->order_id; // "1234"
|
||||
$payment->method; // PaymentMethod::Ideal, a raw string, or null
|
||||
$payment->getCheckoutUrl(); // "https://www.mollie.com/checkout/select-method/7UhSN1zuXS"
|
||||
```
|
||||
|
||||
## Additional Notes
|
||||
|
||||
- `status` is `PaymentStatus|string` and `method` is `PaymentMethod|string|null`; normalise with an `instanceof` check before printing or persisting
|
||||
- The iDEAL payment method is only available for payments in EUR
|
||||
- The bank selection is now handled by iDEAL
|
||||
- The webhook will be called when the payment status changes, so make sure to implement the webhook handler to process status updates
|
||||
@@ -0,0 +1,74 @@
|
||||
# Create a Payment with OAuth
|
||||
|
||||
How to create a payment using OAuth authentication with the Mollie API.
|
||||
|
||||
## The Code
|
||||
|
||||
```php
|
||||
use Mollie\Api\Http\Data\Money;
|
||||
use Mollie\Api\Http\Requests\CreatePaymentRequest;
|
||||
use Mollie\Api\Http\Requests\GetPaginatedProfilesRequest;
|
||||
|
||||
try {
|
||||
// Initialize the Mollie client with your OAuth access token
|
||||
$mollie = new \Mollie\Api\MollieApiClient();
|
||||
$mollie->setAccessToken('access_xxx');
|
||||
|
||||
// Get the first available profile since OAuth tokens don't belong to a specific profile
|
||||
$profiles = $mollie->send(new GetPaginatedProfilesRequest);
|
||||
|
||||
$profile = $profiles[0]; // Select the correct profile for this merchant
|
||||
|
||||
// Generate a unique order ID
|
||||
$orderId = time();
|
||||
|
||||
// Create the payment
|
||||
$payment = $mollie->send(
|
||||
new CreatePaymentRequest(
|
||||
profileId: $profile->id, // Required when using OAuth
|
||||
description: "Order #{$orderId}",
|
||||
amount: new Money(currency: 'EUR', value: '10.00'),
|
||||
redirectUrl: 'https://example.com/return.php?order_id=' . $orderId,
|
||||
cancelUrl: 'https://example.com/cancel.php',
|
||||
webhookUrl: 'https://example.com/webhook.php',
|
||||
metadata: ['order_id' => $orderId]
|
||||
)
|
||||
);
|
||||
|
||||
// Redirect the customer to complete the payment
|
||||
header('Location: ' . $payment->getCheckoutUrl(), true, 303);
|
||||
} catch (\Mollie\Api\Exceptions\ApiException $e) {
|
||||
echo "API call failed: " . htmlspecialchars($e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
## The Response
|
||||
|
||||
```php
|
||||
$payment->id; // "tr_7UhSN1zuXS"
|
||||
$payment->status; // PaymentStatus::Open, or the raw string for an unknown value
|
||||
$payment->amount->currency; // "EUR"
|
||||
$payment->amount->value; // "10.00"
|
||||
$payment->description; // "Order #1234"
|
||||
$payment->metadata; // Object containing order_id
|
||||
$payment->profileId; // "pfl_v9hTwCvYqw"
|
||||
$payment->createdAt; // "2024-02-24T12:13:14+00:00" (or null)
|
||||
```
|
||||
|
||||
`status` is `PaymentStatus|string`, so normalise it before printing or storing it:
|
||||
|
||||
```php
|
||||
use Mollie\Api\Types\PaymentStatus;
|
||||
|
||||
$status = $payment->status instanceof PaymentStatus
|
||||
? $payment->status->value
|
||||
: $payment->status;
|
||||
```
|
||||
|
||||
## Additional Notes
|
||||
|
||||
- OAuth access tokens don't belong to a specific profile, so you need to specify the `profileId` parameter
|
||||
- Get the profile ID by listing the available profiles with `GetPaginatedProfilesRequest`
|
||||
- OAuth tokens are required for certain features like routing payments
|
||||
- Make sure to handle the webhook to process payment status updates
|
||||
- Store your OAuth tokens securely and refresh them when needed
|
||||
@@ -0,0 +1,63 @@
|
||||
# Create a Payment
|
||||
|
||||
How to prepare a new payment with the Mollie API.
|
||||
|
||||
## The Code
|
||||
|
||||
```php
|
||||
use Mollie\Api\Http\Data\Money;
|
||||
use Mollie\Api\Http\Requests\CreatePaymentRequest;
|
||||
|
||||
try {
|
||||
// Return type is Payment, inferred via send()'s @template — no @var needed
|
||||
$payment = $mollie->send(
|
||||
new CreatePaymentRequest(
|
||||
description: "Order #{$orderId}",
|
||||
amount: Money::euro('10.00'),
|
||||
// or: amount: Money::of('EUR')->minorUnits(1000),
|
||||
redirectUrl: 'https://example.org/return',
|
||||
cancelUrl: 'https://example.org/cancel',
|
||||
webhookUrl: 'https://example.org/webhook',
|
||||
metadata: ['order_id' => $orderId]
|
||||
)
|
||||
);
|
||||
|
||||
// Get the checkout URL to redirect the customer to
|
||||
$checkoutUrl = $payment->getCheckoutUrl();
|
||||
} catch (\Mollie\Api\Exceptions\ApiException $e) {
|
||||
echo "API call failed: " . htmlspecialchars($e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
## The Response
|
||||
|
||||
```php
|
||||
$payment->id; // "tr_7UhSN1zuXS"
|
||||
$payment->status; // PaymentStatus::Open (enum) | "open" string fallback for unknown values
|
||||
$payment->amount; // Mollie\Api\Http\Data\Money (readonly value object)
|
||||
$payment->amount->currency; // "EUR"
|
||||
$payment->amount->value; // "10.00"
|
||||
$payment->description; // "Order #1234"
|
||||
$payment->metadata->order_id; // "1234"
|
||||
$payment->getCheckoutUrl(); // "https://www.mollie.com/checkout/select-method/7UhSN1zuXS"
|
||||
```
|
||||
|
||||
Compare statuses against the enum cases (recommended) or string values:
|
||||
|
||||
```php
|
||||
use Mollie\Api\Types\PaymentStatus;
|
||||
|
||||
if ($payment->status === PaymentStatus::Paid) {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
## Additional Notes
|
||||
|
||||
- Always use strings for the amount value to ensure correct decimal precision
|
||||
- The payment `status` will be `open` when initially created
|
||||
- Store the payment `id` in your database for reference
|
||||
- Use `webhookUrl` to get notified of payment status changes
|
||||
- The `redirectUrl` is where your customer will be redirected after the payment
|
||||
- You can store any custom data in the `metadata` object
|
||||
- The checkout URL from `getCheckoutUrl()` is where you should redirect your customer to complete the payment
|
||||
@@ -0,0 +1,101 @@
|
||||
# Create a Routed Payment
|
||||
|
||||
How to create a payment with routing rules using the Mollie API. Routed payments allow you to split payments between connected accounts.
|
||||
|
||||
## The Code
|
||||
|
||||
```php
|
||||
use Mollie\Api\Http\Data\DataCollection;
|
||||
use Mollie\Api\Http\Data\Money;
|
||||
use Mollie\Api\Http\Data\PaymentRoute;
|
||||
use Mollie\Api\Http\Requests\CreatePaymentRequest;
|
||||
use Mollie\Api\Types\PaymentStatus;
|
||||
|
||||
try {
|
||||
// Initialize the Mollie client with your OAuth access token
|
||||
$mollie = new \Mollie\Api\MollieApiClient();
|
||||
$mollie->setAccessToken('access_xxx');
|
||||
|
||||
// Generate a unique order ID
|
||||
$orderId = time();
|
||||
|
||||
// Create the payment with routing rules
|
||||
$payment = $mollie->send(
|
||||
new CreatePaymentRequest(
|
||||
profileId: 'pfl_v9hTwCvYqw',
|
||||
description: "Order #{$orderId}",
|
||||
amount: new Money(currency: 'EUR', value: '10.00'),
|
||||
redirectUrl: 'https://example.com/return.php?order_id=' . $orderId,
|
||||
cancelUrl: 'https://example.com/cancel.php',
|
||||
webhookUrl: 'https://example.com/webhook.php',
|
||||
routing: DataCollection::collect([
|
||||
new PaymentRoute(
|
||||
amount: new Money(currency: 'EUR', value: '7.50'),
|
||||
organizationId: 'org_23456'
|
||||
),
|
||||
])
|
||||
)
|
||||
);
|
||||
|
||||
// Redirect the customer to complete the payment
|
||||
header('Location: ' . $payment->getCheckoutUrl(), true, 303);
|
||||
} catch (\Mollie\Api\Exceptions\ApiException $e) {
|
||||
echo "API call failed: " . htmlspecialchars($e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
### With a Future Release Date
|
||||
|
||||
You can also specify when the routed funds should become available on the connected account's balance. `delayUntil` takes a `Date` or any `DateTimeInterface`, not a raw string:
|
||||
|
||||
```php
|
||||
use Mollie\Api\Http\Data\Date;
|
||||
|
||||
$payment = $mollie->send(
|
||||
new CreatePaymentRequest(
|
||||
profileId: 'pfl_v9hTwCvYqw',
|
||||
description: "Order #{$orderId}",
|
||||
amount: new Money(currency: 'EUR', value: '10.00'),
|
||||
redirectUrl: 'https://example.com/return.php?order_id=' . $orderId,
|
||||
cancelUrl: 'https://example.com/cancel.php',
|
||||
webhookUrl: 'https://example.com/webhook.php',
|
||||
routing: DataCollection::collect([
|
||||
new PaymentRoute(
|
||||
amount: new Money(currency: 'EUR', value: '7.50'),
|
||||
organizationId: 'org_23456',
|
||||
delayUntil: new Date('2025-01-01')
|
||||
),
|
||||
])
|
||||
)
|
||||
);
|
||||
```
|
||||
|
||||
## The Response
|
||||
|
||||
```php
|
||||
$payment->id; // "tr_7UhSN1zuXS"
|
||||
$payment->status; // PaymentStatus::Open, or the raw string for an unknown value
|
||||
$payment->amount->currency; // "EUR"
|
||||
$payment->amount->value; // "10.00"
|
||||
$payment->description; // "Order #1234"
|
||||
$payment->routing; // array of routing rules (or null)
|
||||
$payment->createdAt; // "2024-02-24T12:13:14+00:00"
|
||||
```
|
||||
|
||||
`status` is `PaymentStatus|string`, so normalise it before printing or storing it:
|
||||
|
||||
```php
|
||||
$status = $payment->status instanceof PaymentStatus
|
||||
? $payment->status->value
|
||||
: $payment->status;
|
||||
```
|
||||
|
||||
## Additional Notes
|
||||
|
||||
- Pass routes as a `DataCollection` of `Mollie\Api\Http\Data\PaymentRoute` objects; each route names the destination organization through `organizationId`
|
||||
- Split payments (routing) must be enabled on your account first. Contact Mollie support to enable this feature
|
||||
- You need an OAuth access token to create routed payments
|
||||
- The sum of routed amounts cannot exceed the payment amount
|
||||
- `delayUntil` must be in the future; pass a `Date` (which formats as 'YYYY-MM-DD') or a `DateTimeInterface`
|
||||
- Routing rules are only available for certain payment methods
|
||||
- Make sure to handle the webhook to process payment status updates
|
||||
@@ -0,0 +1,97 @@
|
||||
# Handle Payment Webhooks
|
||||
|
||||
How to handle payment status updates via webhooks from the Mollie API.
|
||||
|
||||
## The Code
|
||||
|
||||
```php
|
||||
use Mollie\Api\Http\Requests\GetPaymentRequest;
|
||||
|
||||
try {
|
||||
// Retrieve the payment's current state
|
||||
$payment = $mollie->send(
|
||||
new GetPaymentRequest(
|
||||
id: $_POST['id']
|
||||
)
|
||||
);
|
||||
$orderId = $payment->metadata->order_id;
|
||||
|
||||
|
||||
|
||||
// First handle status changes
|
||||
if ($payment->status !== $previousPaymentStatus) {
|
||||
// Update your order administration with the new status
|
||||
updateOrder($orderId, $payment->status);
|
||||
|
||||
// Handle the status change
|
||||
if ($payment->isPaid()) {
|
||||
// The payment is paid
|
||||
// Start the process of delivering the product to the customer
|
||||
startDeliveryProcess($orderId);
|
||||
} elseif ($payment->isFailed()) {
|
||||
// The payment has failed
|
||||
// Notify the customer
|
||||
notifyCustomerOfFailure($orderId);
|
||||
} elseif ($payment->isExpired()) {
|
||||
// The payment is expired
|
||||
// Notify the customer
|
||||
notifyCustomerOfExpiration($orderId);
|
||||
} elseif ($payment->isCanceled()) {
|
||||
// The payment is canceled
|
||||
// Notify the customer
|
||||
notifyCustomerOfCancellation($orderId);
|
||||
}
|
||||
}
|
||||
|
||||
// Then handle refunds and chargebacks (these don't change the payment status)
|
||||
if ($payment->hasRefunds()) {
|
||||
// The payment has possibly been (partially) refunded
|
||||
// Note: the payment status remains "paid"
|
||||
processPotentialRefund($orderId);
|
||||
}
|
||||
|
||||
if ($payment->hasChargebacks()) {
|
||||
// The payment has possibly been (partially) charged back
|
||||
// Note: the payment status remains "paid"
|
||||
processPotentialChargeback($orderId);
|
||||
}
|
||||
|
||||
// Always return 200 OK to Mollie
|
||||
http_response_code(200);
|
||||
} catch (\Mollie\Api\Exceptions\ApiException $e) {
|
||||
// Handle the error
|
||||
logError($e->getMessage());
|
||||
http_response_code(500);
|
||||
}
|
||||
```
|
||||
|
||||
## The Response
|
||||
|
||||
```php
|
||||
$payment->id; // "tr_7UhSN1zuXS"
|
||||
$payment->status; // PaymentStatus::Paid
|
||||
$payment->amount->currency; // "EUR"
|
||||
$payment->amount->value; // "10.00"
|
||||
$payment->description; // "Order #1234"
|
||||
$payment->metadata; // Object containing order_id
|
||||
$payment->createdAt; // "2024-02-24T12:13:14+00:00"
|
||||
$payment->paidAt; // "2024-02-24T12:15:00+00:00"
|
||||
```
|
||||
|
||||
## Additional Notes
|
||||
|
||||
- Handle webhooks in the correct order:
|
||||
1. First check for payment status changes
|
||||
2. Then handle refunds and chargebacks (these don't change the payment status).
|
||||
- When completing a payment, the webhook may be called _after_ the customer has already been redirected to the payment's `redirectUrl`.
|
||||
- A payment can have multiple partial refunds and multiple partial chargebacks.
|
||||
- Always respond with a 200 OK status code, even when the payment status is not successful
|
||||
- Process the webhook quickly (within 2 seconds) to avoid timeouts
|
||||
- Use the payment status helper methods (`$payment->isPaid()`, `$payment->isFailed()`, etc.) for reliable status checks
|
||||
- Store the payment status in your database to track the order status
|
||||
- The webhook may be called multiple times for the same payment as Mollie will retry the webhook call.
|
||||
- Webhooks are sent asynchronously, so there might be a delay
|
||||
- Test your webhook implementation thoroughly with different payment scenarios, including:
|
||||
- Status changes (paid, failed, expired, etc.)
|
||||
- Refunds (full and partial)
|
||||
- Chargebacks
|
||||
@@ -0,0 +1,67 @@
|
||||
# List Payment Methods
|
||||
|
||||
How to retrieve all available payment methods with the Mollie API.
|
||||
|
||||
## The Code
|
||||
|
||||
```php
|
||||
use Mollie\Api\Http\Data\Money;
|
||||
use Mollie\Api\Http\Requests\GetAllMethodsRequest;
|
||||
|
||||
try {
|
||||
$methods = $mollie->send(
|
||||
new GetAllMethodsRequest(
|
||||
includeIssuers: false,
|
||||
includePricing: false,
|
||||
locale: 'nl_NL',
|
||||
amount: new Money(currency: 'EUR', value: '100.00')
|
||||
)
|
||||
);
|
||||
|
||||
foreach ($methods as $method) {
|
||||
// Method::$image is ?stdClass — guard it before reading the sizes.
|
||||
$image = $method->image;
|
||||
|
||||
echo '<div style="line-height:40px; vertical-align:top">';
|
||||
|
||||
if ($image !== null) {
|
||||
echo '<img src="' . htmlspecialchars($image->size1x) . '" srcset="' . htmlspecialchars($image->size2x) . ' 2x"> ';
|
||||
}
|
||||
|
||||
echo htmlspecialchars($method->description) . ' (' . htmlspecialchars($method->id) . ')';
|
||||
echo '</div>';
|
||||
}
|
||||
} catch (\Mollie\Api\Exceptions\ApiException $e) {
|
||||
echo "API call failed: " . htmlspecialchars($e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
## The Response
|
||||
|
||||
```php
|
||||
$method->id; // "ideal"
|
||||
$method->description; // "iDEAL"
|
||||
$method->image; // stdClass with size1x/size2x/svg, or null
|
||||
$method->minimumAmount; // Mollie\Api\Http\Data\Money, or null
|
||||
$method->maximumAmount; // Mollie\Api\Http\Data\Money, or null
|
||||
```
|
||||
|
||||
`image`, `minimumAmount` and `maximumAmount` are all nullable, so read them
|
||||
through a local variable rather than chaining off the property:
|
||||
|
||||
```php
|
||||
$minimum = $method->minimumAmount;
|
||||
$maximum = $method->maximumAmount;
|
||||
|
||||
echo 'Minimum: '.($minimum === null ? 'no minimum' : "{$minimum->currency} {$minimum->value}")."\n";
|
||||
echo 'Maximum: '.($maximum === null ? 'no maximum' : "{$maximum->currency} {$maximum->value}")."\n";
|
||||
```
|
||||
|
||||
## Additional Notes
|
||||
|
||||
- Use `sequenceType` to filter methods available for recurring payments
|
||||
- The `locale` parameter affects translations of method names and descriptions
|
||||
- The `amount` parameter filters methods available for that specific amount
|
||||
- The `billingCountry` parameter filters methods available in that country
|
||||
- Most methods include image URLs for regular (1x) and retina (2x) displays, but `image` can be `null`
|
||||
- Methods may have minimum and maximum amount constraints; both are `null` when unconstrained
|
||||
@@ -0,0 +1,65 @@
|
||||
# List Payments
|
||||
|
||||
How to retrieve a list of payments from the Mollie API.
|
||||
|
||||
## The Code
|
||||
|
||||
```php
|
||||
use Mollie\Api\Http\Requests\GetPaginatedPaymentsRequest;
|
||||
use Mollie\Api\Types\PaymentStatus;
|
||||
|
||||
try {
|
||||
// Use the lazy iterator to walk every page transparently — no manual next() loop
|
||||
foreach ($mollie->payments->iterator() as $payment) {
|
||||
// ->value alone breaks the moment Mollie returns a status this
|
||||
// release has no case for, because the property is then a raw string.
|
||||
$status = $payment->status instanceof PaymentStatus
|
||||
? $payment->status->value
|
||||
: $payment->status;
|
||||
|
||||
echo "Payment {$payment->id}:\n";
|
||||
echo "- Description: {$payment->description}\n";
|
||||
echo "- Amount: {$payment->amount->currency} {$payment->amount->value}\n";
|
||||
echo "- Status: {$status}\n";
|
||||
|
||||
if ($payment->hasRefunds()) {
|
||||
echo "- Has been (partially) refunded\n";
|
||||
}
|
||||
|
||||
if ($payment->hasChargebacks()) {
|
||||
echo "- Has been charged back\n";
|
||||
}
|
||||
|
||||
if ($payment->canBeRefunded() && $payment->amountRemaining->currency === 'EUR' && floatval($payment->amountRemaining->value) >= 2.00) {
|
||||
echo "- Can be refunded\n";
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
}
|
||||
} catch (\Mollie\Api\Exceptions\ApiException $e) {
|
||||
echo "API call failed: " . htmlspecialchars($e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
## The Response
|
||||
|
||||
```php
|
||||
$payment->id; // "tr_7UhSN1zuXS"
|
||||
$payment->status; // PaymentStatus::Paid, or the raw string for an unknown value
|
||||
$payment->amount->currency; // "EUR"
|
||||
$payment->amount->value; // "10.00"
|
||||
$payment->description; // "Order #1234"
|
||||
$payment->metadata; // Object containing any custom metadata
|
||||
$payment->createdAt; // "2024-02-24T12:13:14+00:00" (or null)
|
||||
$payment->paidAt; // "2024-02-24T12:15:00+00:00" (or null)
|
||||
$payment->method; // PaymentMethod::Ideal, a raw string, or null
|
||||
```
|
||||
|
||||
## Additional Notes
|
||||
|
||||
- Payments are returned in descending order by creation date (newest first)
|
||||
- `iterator()` lazily fetches each page on demand — only one page is held in memory at a time
|
||||
- For manual page control, send a `GetPaginatedPaymentsRequest` and call `->next()` on the returned cursor collection
|
||||
- `status` is `PaymentStatus|string`. Check it with helpers like `isPaid()` and `isCanceled()`, or with `Utility::equals($payment->status, PaymentStatus::Paid)`; reading `->value` unconditionally fails on a forward-compatible string
|
||||
- Use `hasRefunds()` and `hasChargebacks()` to check if a payment has been refunded or charged back
|
||||
- Use `canBeRefunded()` to check if a payment can still be refunded
|
||||
@@ -0,0 +1,77 @@
|
||||
# Refund a Payment
|
||||
|
||||
How to refund a payment using the Mollie API.
|
||||
|
||||
## The Code
|
||||
|
||||
```php
|
||||
use Mollie\Api\Http\Data\Money;
|
||||
use Mollie\Api\Http\Requests\GetPaymentRequest;
|
||||
use Mollie\Api\Http\Requests\CreatePaymentRefundRequest;
|
||||
use Mollie\Api\Types\RefundStatus;
|
||||
|
||||
try {
|
||||
// Retrieve the payment you want to refund
|
||||
$payment = $mollie->send(
|
||||
new GetPaymentRequest(
|
||||
id: 'tr_WDqYK6vllg'
|
||||
)
|
||||
);
|
||||
|
||||
// Check if the payment can be refunded
|
||||
if ($payment->canBeRefunded() && $payment->amountRemaining->currency === 'EUR' && floatval($payment->amountRemaining->value) >= 2.00) {
|
||||
// Refund € 2,00 of the payment
|
||||
// Note: Using named parameters to avoid PHP 8+ deprecation warnings
|
||||
// Alternative: Use factory method CreatePaymentRefundRequest::for($paymentId, Money::euro('2.00'), 'Description')
|
||||
$refund = $mollie->send(
|
||||
new CreatePaymentRefundRequest(
|
||||
paymentId: $payment->id,
|
||||
amount: Money::euro('2.00'),
|
||||
description: 'Order cancelled by customer'
|
||||
)
|
||||
);
|
||||
|
||||
echo "{$refund->amount->currency} {$refund->amount->value} of payment {$payment->id} refunded.\n";
|
||||
} else {
|
||||
echo "Payment {$payment->id} cannot be refunded.\n";
|
||||
}
|
||||
|
||||
// List all refunds for this payment
|
||||
foreach ($payment->refunds() as $refund) {
|
||||
// status is RefundStatus|string|null: an enum case when this release
|
||||
// knows the value, the raw string when Mollie ships a new one.
|
||||
// Interpolating the property directly throws on an enum case.
|
||||
$status = $refund->status instanceof RefundStatus
|
||||
? $refund->status->value
|
||||
: $refund->status ?? 'unknown';
|
||||
|
||||
echo "Refund {$refund->id}:\n";
|
||||
echo '- Description: '.($refund->description ?? 'no description')."\n";
|
||||
echo "- Amount: {$refund->amount->currency} {$refund->amount->value}\n";
|
||||
echo "- Status: {$status}\n\n";
|
||||
}
|
||||
} catch (\Mollie\Api\Exceptions\ApiException $e) {
|
||||
echo "API call failed: " . htmlspecialchars($e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
## The Response
|
||||
|
||||
```php
|
||||
$refund->id; // "re_4qqhO89gsT"
|
||||
$refund->amount->currency; // "EUR"
|
||||
$refund->amount->value; // "2.00"
|
||||
$refund->status; // RefundStatus case, raw string, or null
|
||||
$refund->description; // "Order cancelled by customer" (or null)
|
||||
$refund->createdAt; // "2024-02-24T12:13:14+00:00"
|
||||
$refund->paymentId; // "tr_WDqYK6vllg"
|
||||
```
|
||||
|
||||
## Additional Notes
|
||||
|
||||
- Not all payments can be refunded. Use `canBeRefunded()` to check if a payment can be refunded
|
||||
- You can do partial refunds by specifying a lower amount than the payment amount
|
||||
- Refunds are not instant. Check the refund status to see if it was successful
|
||||
- The payment must be in the `paid` status to be refundable
|
||||
- Some payment methods may have additional requirements or limitations for refunds
|
||||
- `RefundStatus` covers `Queued`, `Pending`, `Processing`, `Refunded`, `Failed` and `Canceled`. Compare with `isPending()`, `isProcessing()`, `isFailed()` or `Utility::equals()` so an unrecognised string from a newer API version still behaves predictably
|
||||
@@ -0,0 +1,86 @@
|
||||
# Retrieve Payment Captures
|
||||
|
||||
How to retrieve and list captures for a payment using the Mollie API.
|
||||
|
||||
## Get a Single Capture
|
||||
|
||||
```php
|
||||
use Mollie\Api\Resources\Capture;
|
||||
use Mollie\Api\Http\Requests\GetPaymentCaptureRequest;
|
||||
|
||||
try {
|
||||
// Retrieve a specific capture
|
||||
/** @var Capture $capture */
|
||||
$capture = $mollie->send(
|
||||
new GetPaymentCaptureRequest(
|
||||
paymentId: 'tr_WDqYK6vllg',
|
||||
captureId: 'cpt_4qqhO89gsT'
|
||||
)
|
||||
);
|
||||
|
||||
// Capture::$amount is nullable per the API contract, so guard the deref.
|
||||
$amount = $capture->amount;
|
||||
|
||||
echo $amount === null
|
||||
? "Capture {$capture->id} has no amount\n"
|
||||
: "Captured {$amount->currency} {$amount->value}\n";
|
||||
} catch (\Mollie\Api\Exceptions\ApiException $e) {
|
||||
echo "API call failed: " . htmlspecialchars($e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
## List All Captures
|
||||
|
||||
```php
|
||||
use Mollie\Api\Resources\Capture;
|
||||
use Mollie\Api\Resources\LazyCollection;
|
||||
use Mollie\Api\Http\Requests\GetPaginatedPaymentCapturesRequest;
|
||||
|
||||
try {
|
||||
// List all captures for a payment
|
||||
/** @var LazyCollection $captures */
|
||||
$captures = $mollie->send(
|
||||
(new GetPaginatedPaymentCapturesRequest(
|
||||
paymentId: 'tr_WDqYK6vllg'
|
||||
))->useIterator()
|
||||
);
|
||||
|
||||
/** @var Capture $capture */
|
||||
foreach ($captures as $capture) {
|
||||
$amount = $capture->amount;
|
||||
|
||||
echo "Capture {$capture->id}:\n";
|
||||
echo '- Amount: '.($amount === null ? 'not available' : "{$amount->currency} {$amount->value}")."\n";
|
||||
echo '- Status: '.($capture->status ?? 'unknown')."\n";
|
||||
echo '- Created: '.($capture->createdAt ?? 'unknown')."\n\n";
|
||||
}
|
||||
} catch (\Mollie\Api\Exceptions\ApiException $e) {
|
||||
echo "API call failed: " . htmlspecialchars($e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
## The Response
|
||||
|
||||
```php
|
||||
$capture->id; // "cpt_4qqhO89gsT"
|
||||
$capture->paymentId; // "tr_WDqYK6vllg"
|
||||
$capture->amount; // Money, or null when the API omits it
|
||||
$capture->amount?->currency; // "EUR"
|
||||
$capture->amount?->value; // "5.00"
|
||||
$capture->description; // "Order #12345" (or null)
|
||||
$capture->status; // "pending", "succeeded", "failed" (or null)
|
||||
$capture->createdAt; // "2024-02-24T12:13:14+00:00" (or null)
|
||||
```
|
||||
|
||||
`Capture::$amount` is nullable per the API contract, so guard it (or use `?->`)
|
||||
before reading `currency` or `value`. `status` is a plain nullable string here,
|
||||
not a backed enum.
|
||||
|
||||
## Additional Notes
|
||||
|
||||
- You can only retrieve captures for payments created with `captureMode: 'manual'`
|
||||
- A payment can have multiple captures if partial captures were used
|
||||
- The captures list is paginated, use `next()` to get the next page
|
||||
- The capture status indicates whether the capture was successful
|
||||
- The payment status will change to `paid` once all captures are successful
|
||||
- Make sure to handle the webhook to process capture status updates
|
||||
@@ -0,0 +1,74 @@
|
||||
# Update a Payment
|
||||
|
||||
How to update an existing payment using the Mollie API.
|
||||
|
||||
## The Code
|
||||
|
||||
```php
|
||||
use Mollie\Api\Http\Requests\GetPaymentRequest;
|
||||
use Mollie\Api\Http\Requests\UpdatePaymentRequest;
|
||||
|
||||
try {
|
||||
// First retrieve the payment you want to update
|
||||
$payment = $mollie->send(
|
||||
new GetPaymentRequest(
|
||||
id: 'tr_7UhSN1zuXS'
|
||||
)
|
||||
);
|
||||
|
||||
// Update specific payment fields
|
||||
$newOrderId = 98765;
|
||||
$payment = $mollie->send(
|
||||
new UpdatePaymentRequest(
|
||||
id: $payment->id,
|
||||
description: "Order #{$newOrderId}",
|
||||
redirectUrl: 'https://example.com/return.php?order_id=' . $newOrderId,
|
||||
metadata: ['order_id' => $newOrderId]
|
||||
// Fields we don't specify will keep their current values:
|
||||
// - webhookUrl
|
||||
// - cancelUrl
|
||||
// - etc.
|
||||
)
|
||||
);
|
||||
|
||||
// Redirect the customer to complete the payment
|
||||
header('Location: ' . $payment->getCheckoutUrl(), true, 303);
|
||||
} catch (\Mollie\Api\Exceptions\ApiException $e) {
|
||||
echo "API call failed: " . htmlspecialchars($e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
## The Response
|
||||
|
||||
```php
|
||||
$payment->id; // "tr_7UhSN1zuXS"
|
||||
$payment->status; // PaymentStatus::Open, or the raw string for an unknown value
|
||||
$payment->description; // "Order #98765"
|
||||
$payment->redirectUrl; // "https://example.com/return.php?order_id=98765" (or null)
|
||||
$payment->webhookUrl; // "https://example.com/webhook.php" (or null)
|
||||
$payment->metadata; // Object containing order_id
|
||||
$payment->createdAt; // "2024-02-24T12:13:14+00:00" (or null)
|
||||
```
|
||||
|
||||
`status` is `PaymentStatus|string`, so normalise it before printing or storing it:
|
||||
|
||||
```php
|
||||
use Mollie\Api\Types\PaymentStatus;
|
||||
|
||||
$status = $payment->status instanceof PaymentStatus
|
||||
? $payment->status->value
|
||||
: $payment->status;
|
||||
```
|
||||
|
||||
## Additional Notes
|
||||
|
||||
- Only certain fields can be updated, including:
|
||||
- description
|
||||
- redirectUrl
|
||||
- cancelUrl
|
||||
- webhookUrl
|
||||
- metadata
|
||||
- You cannot update the amount or currency of a payment
|
||||
- The payment must be in a state that allows updates (e.g., you cannot update a completed payment)
|
||||
- Make sure to handle the webhook to process payment status updates
|
||||
- `Payment` has no `updatedAt` property; the response returns the updated resource, so re-read the fields you changed
|
||||
Reference in new issue
Block a user