Initial commit
This commit is contained in:
commit
2b9e58beee
822 files changed
+62544
No files matched your search
@@ -0,0 +1,142 @@
|
||||
# Customer Payments
|
||||
|
||||
How to create and manage payments for customers using the Mollie API.
|
||||
|
||||
## First Payment (For Recurring)
|
||||
|
||||
```php
|
||||
use Mollie\Api\Http\Data\Money;
|
||||
use Mollie\Api\Http\Requests\CreateCustomerPaymentRequest;
|
||||
use Mollie\Api\Types\PaymentStatus;
|
||||
use Mollie\Api\Types\SequenceType;
|
||||
|
||||
try {
|
||||
// Create the first payment for a customer
|
||||
$payment = $mollie->send(
|
||||
new CreateCustomerPaymentRequest(
|
||||
customerId: 'cst_8wmqcHMN4U',
|
||||
description: 'First payment - Order #12345',
|
||||
amount: Money::euro('29.95'), // Using convenience method
|
||||
redirectUrl: 'https://example.com/payments/return?order_id=12345',
|
||||
webhookUrl: 'https://example.com/payments/webhook',
|
||||
metadata: [
|
||||
'order_id' => '12345'
|
||||
],
|
||||
sequenceType: SequenceType::First->value // This creates a mandate for future payments
|
||||
)
|
||||
);
|
||||
|
||||
// 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());
|
||||
}
|
||||
```
|
||||
|
||||
## Recurring Payment
|
||||
|
||||
```php
|
||||
use Mollie\Api\Http\Data\Money;
|
||||
use Mollie\Api\Http\Requests\CreateCustomerPaymentRequest;
|
||||
use Mollie\Api\Types\SequenceType;
|
||||
|
||||
try {
|
||||
// Create a recurring payment using the mandate
|
||||
$payment = $mollie->send(
|
||||
new CreateCustomerPaymentRequest(
|
||||
customerId: 'cst_8wmqcHMN4U',
|
||||
description: 'Recurring payment - Order #12346',
|
||||
amount: Money::euro('29.95'), // Using convenience method
|
||||
webhookUrl: 'https://example.com/payments/webhook',
|
||||
metadata: [
|
||||
'order_id' => '12346'
|
||||
],
|
||||
sequenceType: SequenceType::Recurring->value // This uses the mandate created by the first payment
|
||||
)
|
||||
);
|
||||
|
||||
// The payment will be either pending or paid immediately
|
||||
$status = $payment->status instanceof PaymentStatus
|
||||
? $payment->status->value
|
||||
: $payment->status;
|
||||
|
||||
echo "Payment status: {$status}\n";
|
||||
echo "Used mandate: " . ($payment->mandateId ?? 'not assigned') . "\n";
|
||||
} catch (\Mollie\Api\Exceptions\ApiException $e) {
|
||||
echo "API call failed: " . htmlspecialchars($e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
## List Customer Payments
|
||||
|
||||
```php
|
||||
use Mollie\Api\Http\Requests\GetPaginatedCustomerPaymentsRequest;
|
||||
use Mollie\Api\Resources\PaymentCollection;
|
||||
use Mollie\Api\Types\PaymentStatus;
|
||||
|
||||
try {
|
||||
// Get all payments for a customer
|
||||
/** @var PaymentCollection */
|
||||
$payments = $mollie->send(
|
||||
new GetPaginatedCustomerPaymentsRequest(
|
||||
customerId: 'cst_8wmqcHMN4U'
|
||||
)
|
||||
);
|
||||
|
||||
foreach ($payments as $payment) {
|
||||
$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";
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
}
|
||||
} catch (\Mollie\Api\Exceptions\ApiException $e) {
|
||||
echo "API call failed: " . htmlspecialchars($e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
## The Payment Response
|
||||
|
||||
```php
|
||||
$payment->id; // "tr_7UhSN1zuXS"
|
||||
$payment->customerId; // "cst_8wmqcHMN4U"
|
||||
$payment->mode; // "live" or "test"
|
||||
$payment->description; // "Order #12345"
|
||||
$payment->metadata; // Object containing custom metadata
|
||||
$payment->status; // PaymentStatus case, or an unknown raw string
|
||||
$payment->isCancelable; // Whether the payment can be canceled, or null
|
||||
$payment->sequenceType; // SequenceType case, unknown raw string, or null
|
||||
$payment->redirectUrl; // URL to redirect the customer to
|
||||
$payment->webhookUrl; // URL for webhook notifications
|
||||
$payment->createdAt; // "2024-02-24T12:13:14+00:00"
|
||||
```
|
||||
|
||||
## Additional Notes
|
||||
|
||||
- First create a customer before creating customer payments
|
||||
- The first payment creates a mandate for future recurring payments
|
||||
- Sequence types:
|
||||
- `first`: Creates a mandate for future payments
|
||||
- `recurring`: Uses an existing mandate
|
||||
- Recurring payments:
|
||||
- Don't need a `redirectUrl` as they use the stored mandate
|
||||
- Will be executed immediately without customer interaction
|
||||
- May still be pending depending on the payment method
|
||||
- The mandate status determines if recurring payments can be created
|
||||
- Store the payment ID and status in your database
|
||||
- Always implement proper webhook handling
|
||||
- Available payment methods may differ for first and recurring payments
|
||||
- Some payment methods don't support recurring payments
|
||||
@@ -0,0 +1,125 @@
|
||||
# Manage Customers
|
||||
|
||||
How to create, update, and delete customers using the Mollie API.
|
||||
|
||||
## Create a Customer
|
||||
|
||||
```php
|
||||
use Mollie\Api\Http\Requests\CreateCustomerRequest;
|
||||
|
||||
try {
|
||||
// Create a new customer
|
||||
$customer = $mollie->send(
|
||||
new CreateCustomerRequest(
|
||||
name: 'Luke Skywalker',
|
||||
email: 'luke@example.com',
|
||||
locale: 'en_US',
|
||||
metadata: [
|
||||
'isJedi' => true
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
echo "New customer created: {$customer->id}\n";
|
||||
} catch (\Mollie\Api\Exceptions\ApiException $e) {
|
||||
echo "API call failed: " . htmlspecialchars($e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
## Update a Customer
|
||||
|
||||
```php
|
||||
use Mollie\Api\Http\Requests\GetCustomerRequest;
|
||||
use Mollie\Api\Http\Requests\UpdateCustomerRequest;
|
||||
|
||||
try {
|
||||
// First retrieve the customer you want to update
|
||||
$customer = $mollie->send(
|
||||
new GetCustomerRequest(
|
||||
id: 'cst_8wmqcHMN4U'
|
||||
)
|
||||
);
|
||||
|
||||
// Update specific customer fields
|
||||
$customer = $mollie->send(
|
||||
new UpdateCustomerRequest(
|
||||
id: $customer->id,
|
||||
name: 'Luke Sky',
|
||||
email: 'luke@example.com',
|
||||
locale: 'en_US',
|
||||
metadata: [
|
||||
'isJedi' => true
|
||||
]
|
||||
// Fields we don't specify will keep their current values
|
||||
)
|
||||
);
|
||||
|
||||
echo "Customer updated: {$customer->name}\n";
|
||||
} catch (\Mollie\Api\Exceptions\ApiException $e) {
|
||||
echo "API call failed: " . htmlspecialchars($e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
## Delete a Customer
|
||||
|
||||
```php
|
||||
use Mollie\Api\Http\Requests\DeleteCustomerRequest;
|
||||
|
||||
try {
|
||||
// Delete a customer
|
||||
$mollie->send(
|
||||
new DeleteCustomerRequest(
|
||||
id: 'cst_8wmqcHMN4U'
|
||||
)
|
||||
);
|
||||
|
||||
echo "Customer deleted\n";
|
||||
} catch (\Mollie\Api\Exceptions\ApiException $e) {
|
||||
echo "API call failed: " . htmlspecialchars($e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
## The Response
|
||||
|
||||
```php
|
||||
$customer->id; // "cst_8wmqcHMN4U"
|
||||
$customer->name; // "Luke Skywalker"
|
||||
$customer->email; // "luke@example.com"
|
||||
$customer->locale; // "en_US"
|
||||
$customer->metadata; // Object containing custom metadata
|
||||
$customer->mode; // "live" or "test"
|
||||
$customer->createdAt; // "2024-02-24T12:13:14+00:00"
|
||||
```
|
||||
|
||||
## Additional Notes
|
||||
|
||||
- Customers are used to store recurring payment details
|
||||
- Each customer can have multiple mandates for different payment methods
|
||||
- The customer ID is required for:
|
||||
- Creating recurring payments
|
||||
- Creating subscriptions
|
||||
- Retrieving payment history
|
||||
- Customer data should be kept in sync with your own database
|
||||
- Available locales:
|
||||
- `en_US` English (US)
|
||||
- `en_GB` English (UK)
|
||||
- `nl_NL` Dutch (Netherlands)
|
||||
- `nl_BE` Dutch (Belgium)
|
||||
- `fr_FR` French (France)
|
||||
- `fr_BE` French (Belgium)
|
||||
- `de_DE` German (Germany)
|
||||
- `de_AT` German (Austria)
|
||||
- `de_CH` German (Switzerland)
|
||||
- `es_ES` Spanish (Spain)
|
||||
- `ca_ES` Catalan (Spain)
|
||||
- `pt_PT` Portuguese (Portugal)
|
||||
- `it_IT` Italian (Italy)
|
||||
- `nb_NO` Norwegian (Norway)
|
||||
- `sv_SE` Swedish (Sweden)
|
||||
- `fi_FI` Finnish (Finland)
|
||||
- `da_DK` Danish (Denmark)
|
||||
- `is_IS` Icelandic (Iceland)
|
||||
- `hu_HU` Hungarian (Hungary)
|
||||
- `pl_PL` Polish (Poland)
|
||||
- `lv_LV` Latvian (Latvia)
|
||||
- `lt_LT` Lithuanian (Lithuania)
|
||||
Reference in new issue
Block a user