diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 99c16e624..35810719a 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,8 +1,8 @@ ## Specifications - - API Version: + - API Version: + - SDK Version: ## Describe the issue ... - diff --git a/.github/workflows/check_php_syntax.yml b/.github/workflows/check_php_syntax.yml index ed5868e85..93af72e0a 100644 --- a/.github/workflows/check_php_syntax.yml +++ b/.github/workflows/check_php_syntax.yml @@ -3,18 +3,18 @@ on: push: pull_request: schedule: - - cron: '0 0 * * *' + - cron: "0 0 * * *" jobs: tests: runs-on: ubuntu-latest strategy: fail-fast: true matrix: - php: [ 7.2 ] + php: [7.4] name: Check PHP ${{ matrix.php }} syntax steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup PHP uses: shivammathur/setup-php@v2 with: diff --git a/.github/workflows/createzip.yml b/.github/workflows/createzip.yml index 2873d8c84..40da216f8 100644 --- a/.github/workflows/createzip.yml +++ b/.github/workflows/createzip.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup PHP uses: shivammathur/setup-php@v2 with: @@ -38,7 +38,7 @@ jobs: sed -i.bak 's/autoload.php/composer-autoload.php/g' build/vendor/scoper-autoload.php mv build/vendor/scoper-autoload.php build/vendor/autoload.php - name: Install zip - uses: montudor/action-zip@v0.1.1 + uses: montudor/action-zip@v1 - name: Finally, create a zip file with all built files. run: zip -r mollie-api-php.zip examples src vendor composer.json LICENSE README.md working-directory: build diff --git a/.github/workflows/fix-codestyle.yml b/.github/workflows/fix-codestyle.yml new file mode 100644 index 000000000..66be903f0 --- /dev/null +++ b/.github/workflows/fix-codestyle.yml @@ -0,0 +1,33 @@ +name: Fix Code Style + +on: [push] + +jobs: + lint: + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + php: [8.4] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: json, dom, curl, libxml, mbstring + coverage: none + + - name: Install Pint + run: composer global require laravel/pint + + - name: Run Pint + run: pint + + - name: Commit linted files + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: "Fixes coding style" diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/php-cs-fixer.yml deleted file mode 100644 index a83d7080b..000000000 --- a/.github/workflows/php-cs-fixer.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Check & fix styling - -on: [push] - -jobs: - php-cs-fixer: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v2 - with: - ref: ${{ github.head_ref }} - - - name: Run PHP CS Fixer - uses: docker://oskarstark/php-cs-fixer-ga - with: - args: --config=.php-cs-fixer.dist.php --allow-risky=yes - - - name: Commit changes - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: Fix styling diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index dc409b109..c9b246124 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -3,18 +3,18 @@ on: push: pull_request: schedule: - - cron: '0 0 * * *' + - cron: "0 0 * * *" jobs: tests: runs-on: ubuntu-latest strategy: fail-fast: true matrix: - php: [7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3, 8.4] + php: [7.4, 8.0, 8.1, 8.2, 8.3, 8.4] name: PHP - ${{ matrix.php }} steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup PHP uses: shivammathur/setup-php@v2 with: @@ -22,16 +22,15 @@ jobs: extensions: dom, curl, libxml, mbstring, zip tools: composer:v2 coverage: none - - name: Remove PHP CS Fixer dependency to prevent unnecessary dependency collisions + - name: Remove pint dependency to prevent unnecessary dependency collisions run: | - composer remove --dev friendsofphp/php-cs-fixer + composer remove --dev laravel/pint - name: Install dependencies run: | composer update --prefer-dist --no-interaction --no-progress - name: PHPStan - if: ${{ matrix.php >= 7.3 }} run: | - composer require "phpstan/phpstan:1.12.5" + composer require "phpstan/phpstan" --dev vendor/bin/phpstan analyse --no-progress - name: Execute tests - run: vendor/bin/phpunit --verbose + run: vendor/bin/paratest --verbose diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml new file mode 100644 index 000000000..0cdea2336 --- /dev/null +++ b/.github/workflows/update-changelog.yml @@ -0,0 +1,28 @@ +name: "Update Changelog" + +on: + release: + types: [released] + +jobs: + update: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: main + + - name: Update Changelog + uses: stefanzweifel/changelog-updater-action@v1 + with: + latest-version: ${{ github.event.release.name }} + release-notes: ${{ github.event.release.body }} + + - name: Commit updated CHANGELOG + uses: stefanzweifel/git-auto-commit-action@v5 + with: + branch: main + commit_message: Update CHANGELOG + file_pattern: CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..20456c3d7 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,8 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased](https://github.com/mollie/mollie-api-php/compare/v3.0.0...HEAD) diff --git a/README.md b/README.md index faa1275e3..a96330bf7 100644 --- a/README.md +++ b/README.md @@ -32,14 +32,6 @@ The easiest way to install the Mollie API client is by using [Composer](http://g composer require mollie/mollie-api-php ``` -To work with the most recent API version, ensure that you are using a version of this API client that is equal to or greater than 2.0.0. If you prefer to continue using the v1 API, make sure your client version is below 2.0.0. For guidance on transitioning from v1 to v2, please refer to the [migration notes](https://docs.mollie.com/docs/migrating-from-v1-to-v2). - -### Manual Installation ### -If you're not familiar with using composer we've added a ZIP file to the releases containing the API client and all the packages normally installed by composer. -Download the ``mollie-api-php.zip`` from the [releases page](https://github.com/mollie/mollie-api-php/releases). - -Include the ``vendor/autoload.php`` as shown in [Initialize example](https://github.com/mollie/mollie-api-php/blob/master/examples/initialize.php). - ## Usage ## Initializing the Mollie API client, and setting your API key. @@ -49,355 +41,70 @@ $mollie = new \Mollie\Api\MollieApiClient(); $mollie->setApiKey("test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM"); ``` -With the `MollieApiClient` you can now access any of the following endpoints by selecting them as a property of the client: - -| API | Resource | Code | Link to Endpoint file | -| ----------------------- | ----------------------- | -------------------------- | -------------------------------------------------------------------------- | -| **[Balances API](https://docs.mollie.com/reference/v2/balances-api/overview)** | Balance | `$mollie->balances` | [BalanceEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/BalanceEndpoint.php) | -| | Balance Report | `$mollie->balanceReports` | [BalanceReportEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/BalanceReportEndpoint.php) | -| | Balance Transaction | `$mollie->balanceTransactions` | [BalanceTransactionEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/BalanceTransactionEndpoint.php) | -| **[Chargebacks API](https://docs.mollie.com/reference/v2/chargebacks-api/overview)** | Chargeback |`$mollie->chargebacks` | [ChargebackEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/ChargebackEndpoint.php) | -| | Payment Chargeback | `$mollie->paymentChargebacks` | [PaymentChargebackEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/PaymentChargebackEndpoint.php) | -| **[Clients API](https://docs.mollie.com/reference/v2/clients-api/overview)** | Client | `$mollie->clients` | [ClientEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/ClientEndpoint.php) | -| **[Client Links API](https://docs.mollie.com/reference/v2/client-links-api/overview)** | Client Link | `$mollie->clientLinks` | [ClientLinkEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/ClientLinkEndpoint.php) | -| **[Customers API](https://docs.mollie.com/reference/v2/customers-api/overview)** | Customer | `$mollie->customers` | [CustomerEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/CustomerEndpoint.php) | -| | Customer Payment | `$mollie->customerPayments` | [CustomerPaymentsEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/CustomerPaymentsEndpoint.php) | -| **[Invoices API](https://docs.mollie.com/reference/v2/invoices-api/overview)** | Invoice | `$mollie->invoices` | [InvoiceEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/InvoiceEndpoint.php) | -| **[Mandates API](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/MandateEndpoint.php)** | Mandate | `$mollie->mandates` | [MandateEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/MandateEndpoint.php) | -| **[Methods API](https://docs.mollie.com/reference/v2/methods-api/overview)** | Payment Method | `$mollie->methods` | [MethodEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/MethodEndpoint.php) | -| **[Onboarding API](https://docs.mollie.com/reference/v2/onboarding-api/overview)** | Onboarding |`$mollie->onboarding` | [OnboardingEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/OnboardingEndpoint.php) | -| **[Orders API](https://docs.mollie.com/reference/v2/orders-api/overview)** | Order | `$mollie->orders` | [OrderEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/OrderEndpoint.php) | -| | Order Line | `$mollie->orderLines` | [OrderLineEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/OrderLineEndpoint.php) | -| | Order Payment | `$mollie->orderPayments` | [OrderPaymentEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/OrderPaymentEndpoint.php) | -| **[Organizations API](https://docs.mollie.com/reference/v2/organizations-api/overview)** | Organization | `$mollie->organizations` | [OrganizationEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/OrganizationEndpoint.php) | -| | Organization Partner | `$mollie->organizationPartners` | [OrganizationPartnerEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/OrganizationPartnerEndpoint.php) | -| **[Captures API](https://docs.mollie.com/reference/v2/captures-api/overview)** | Payment Captures | `$mollie->organizations` | [PaymentCaptureEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/PaymentCaptureEndpoint.php) | -| **[Payments API](https://docs.mollie.com/reference/v2/payments-api/overview)** | Payment | `$mollie->payments` | [PaymentEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/PaymentEndpoint.php) | -| | Payment Route | `$mollie->paymentRoutes` | [PaymentRouteEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/PaymentRouteEndpoint.php) | -| **[Payment links API](https://docs.mollie.com/reference/v2/payment-links-api/overview)** | Payment Link | `$mollie->paymentLinks` | [PaymentLinkEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/PaymentLinkEndpoint.php) | -| **[Permissions API](https://docs.mollie.com/reference/v2/permissions-api/overview)** | Permission | `$mollie->permissions` | [PermissionEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/PermissionEndpoint.php) | -| **[Profile API](https://docs.mollie.com/reference/v2/profiles-api/overview)** | Profile | `$mollie->profiles` | [ProfileEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/ProfileEndpoint.php) | -| | Profile Method | `$mollie->profileMethods` | [ProfileMethodEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/ProfileMethodEndpoint.php) | -| **[Refund API](https://docs.mollie.com/reference/v2/refunds-api/overview)** | Refund | `$mollie->refunds` | [RefundEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/RefundEndpoint.php) | -| | Order Refund | `$mollie->orderRefunds` | [OrderRefundEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/OrderRefundEndpoint.php) | -| | Payment Refund | `$mollie->paymentRefunds` | [PaymentRefundEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/PaymentRefundEndpoint.php) | -| **[Settlements API](https://docs.mollie.com/reference/v2/settlements-api/overview)** | Settlement | `$mollie->settlements` | [SettlementsEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/SettlementsEndpoint.php) | -| | Settlement Capture | `$mollie->settlementCaptures` | [SettlementCaptureEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/SettlementCaptureEndpoint.php) | -| | Settlement Chargeback | `$mollie->settlementChargebacks` | [SettlementChargebackEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/SettlementChargebackEndpoint.php) | -| | Settlement Payment | `$mollie->settlementPayments` | [SettlementPaymentEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/SettlementPaymentEndpoint.php) | -| | Settlement Refund | `$mollie->settlementRefunds` | [SettlementRefundEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/SettlementRefundEndpoint.php) | -| **[Shipments API](https://docs.mollie.com/reference/v2/shipments-api/overview)** | Shipment | `$mollie->shipments` | [ShipmentEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/ShipmentEndpoint.php) | -| **[Subscriptions API](https://docs.mollie.com/reference/v2/subscriptions-api/overview)** | Subscription | `$mollie->subscriptions` | [SubscriptionEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/SubscriptionEndpoint.php) | -| **[Terminal API](https://docs.mollie.com/reference/v2/terminals-api/overview)** | Terminal | `$mollie->terminals` | [TerminalEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/TerminalEndpoint.php) | -| **[Wallets API](https://docs.mollie.com/reference/v2/wallets-api/overview)** | Wallet | `$mollie->wallets` | [WalletEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/WalletEndpoint.php) | - Find our full documentation online on [docs.mollie.com](https://docs.mollie.com). -### Orders ### -#### Creating Orders #### -**[Create Order reference](https://docs.mollie.com/reference/v2/orders-api/create-order)** - -```php -$order = $mollie->orders->create([ - "amount" => [ - "value" => "1027.99", - "currency" => "EUR", - ], - "billingAddress" => [ - "streetAndNumber" => "Keizersgracht 313", - "postalCode" => "1016 EE", - "city" => "Amsterdam", - "country" => "nl", - "givenName" => "Luke", - "familyName" => "Skywalker", - "email" => "luke@skywalker.com", - ], - "shippingAddress" => [ - "streetAndNumber" => "Keizersgracht 313", - "postalCode" => "1016 EE", - "city" => "Amsterdam", - "country" => "nl", - "givenName" => "Luke", - "familyName" => "Skywalker", - "email" => "luke@skywalker.com", - ], - "metadata" => [ - "some" => "data", - ], - "consumerDateOfBirth" => "1958-01-31", - "locale" => "en_US", - "orderNumber" => "1234", - "redirectUrl" => "https://your_domain.com/return?some_other_info=foo", - "webhookUrl" => "https://your_domain.com/webhook", - "method" => "ideal", - "lines" => [ - [ - "sku" => "5702016116977", - "name" => "LEGO 42083 Bugatti Chiron", - "productUrl" => "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", - "imageUrl" => 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$', - "quantity" => 2, - "vatRate" => "21.00", - "unitPrice" => [ - "currency" => "EUR", - "value" => "399.00", - ], - "totalAmount" => [ - "currency" => "EUR", - "value" => "698.00", - ], - "discountAmount" => [ - "currency" => "EUR", - "value" => "100.00", - ], - "vatAmount" => [ - "currency" => "EUR", - "value" => "121.14", - ], - ], - // more order line items - ], -]); -``` - -_After creation, the order id is available in the `$order->id` property. You should store this id with your order._ - -After storing the order id you can send the customer off to complete the order payment using `$order->getCheckoutUrl()`. - -```php -header("Location: " . $order->getCheckoutUrl(), true, 303); -``` - -_This header location should always be a GET, thus we enforce 303 http response code_ - -For an order create example, see [Example - New Order](https://github.com/mollie/mollie-api-php/blob/master/examples/orders/create-order.php). - -#### Updating Orders #### -**[Update Order Documentation](https://docs.mollie.com/reference/v2/orders-api/update-order)** - -```php -$order = $mollie->orders->get("ord_kEn1PlbGa"); -$order->billingAddress->organizationName = "Mollie B.V."; -$order->billingAddress->streetAndNumber = "Keizersgracht 126"; -$order->billingAddress->city = "Amsterdam"; -$order->billingAddress->region = "Noord-Holland"; -$order->billingAddress->postalCode = "1234AB"; -$order->billingAddress->country = "NL"; -$order->billingAddress->title = "Dhr"; -$order->billingAddress->givenName = "Piet"; -$order->billingAddress->familyName = "Mondriaan"; -$order->billingAddress->email = "piet@mondriaan.com"; -$order->billingAddress->phone = "+31208202070"; -$order->update(); -``` - -#### Refunding Orders #### -##### Complete ##### -```php -$order = $mollie->orders->get('ord_8wmqcHMN4U'); -$refund = $order->refundAll(); - -echo 'Refund ' . $refund->id . ' was created for order ' . $order->id; -``` - -##### Partially ##### -When executing a partial refund you have to list all order line items that should be refunded. - -```php -$order = $mollie->orders->get('ord_8wmqcHMN4U'); -$refund = $order->refund([ - 'lines' => [ - [ - 'id' => 'odl_dgtxyl', - 'quantity' => 1, - ], - ], - "description" => "Required quantity not in stock, refunding one photo book.", -]); -``` - -#### Cancel Orders #### -**[Cancel Order Documentation](https://docs.mollie.com/reference/v2/orders-api/cancel-order)** - -_When canceling an order it is crucial to check if the order is cancelable before executing the cancel action. For more information see the [possible order statuses](https://docs.mollie.com/orders/status-changes#possible-statuses-for-orders)._ - +#### Example usage #### ```php -$order = $mollie->orders->get("ord_pbjz8x"); - -if ($order->isCancelable) { - $canceledOrder = $order->cancel(); - echo "Your order " . $order->id . " has been canceled."; -} else { - echo "Unable to cancel your order " . $order->id . "."; -} -``` +use Mollie\Api\Http\Data\Money; +use Mollie\Api\Http\Data\CreatePaymentPayload; +use Mollie\Api\Http\Requests\CreatePaymentRequest; -#### Order webhook #### -When the order status changes, the `webhookUrl` you specified during order creation will be called. You can use the `id` from the POST parameters to check the status and take appropriate actions. For more details, refer to [Example - Webhook](https://github.com/mollie/mollie-api-php/blob/master/examples/orders/webhook.php). +$payload = new CreatePaymentPayload( + description: 'My first API payment', + amount: new Money('EUR', '10.00'), + redirectUrl: 'https://webshop.example.org/order/12345/', + webhookUrl: 'https://webshop.example.org/mollie-webhook/' +); -### Payments ### -#### Payment Reception Process #### -**[Payment Reception Process documentation](https://docs.mollie.com/payments/accepting-payments#working-with-the-payments-api)** +/** @var Mollie\Api\Http\Response $response */ +$response = $mollie->send(new CreatePaymentRequest($payload)); -To ensure a successful payment reception, you should follow these steps: - -1. Utilize the Mollie API client to initiate a payment. Specify the desired amount, currency, description, and optionally, a payment method. It's crucial to define a unique redirect URL where the customer should be directed after completing the payment. - -2. Immediately upon payment completion, our platform will initiate an asynchronous request to the configured webhook. This enables you to retrieve payment details, ensuring you know precisely when to commence processing the customer's order. - -3. The customer is redirected to the URL from step (1) and should be pleased to find that the order has been paid and is now in the processing stage. - - -#### Creating Payments #### -**[Create Payment Documentation](https://docs.mollie.com/reference/v2/payments-api/create-payment)** - -```php -$payment = $mollie->payments->create([ - "amount" => [ - "currency" => "EUR", - "value" => "10.00" - ], - "description" => "My first API payment", - "redirectUrl" => "https://webshop.example.org/order/12345/", - "webhookUrl" => "https://webshop.example.org/mollie-webhook/", -]); +/** @var Mollie\Api\Resources\Payment $payment */ +$payment = $response->toResource(); ``` -_After creation, the payment id is available in the `$payment->id` property. You should store this id with your order._ - -After storing the payment id you can send the customer to the checkout using `$payment->getCheckoutUrl()`. -```php -header("Location: " . $payment->getCheckoutUrl(), true, 303); -``` - -_This header location should always be a GET, thus we enforce 303 http response code_ - -For a payment create example, see [Example - New Payment](https://github.com/mollie/mollie-api-php/blob/master/examples/payments/create-payment.php). - -##### Multicurrency ##### -Since API v2.0 it is now possible to create non-EUR payments for your customers. -A full list of available currencies can be found [in our documentation](https://docs.mollie.com/guides/multicurrency). - -```php -$payment = $mollie->payments->create([ - "amount" => [ - "currency" => "USD", - "value" => "10.00" - ], - //... -]); -``` -_After creation, the `settlementAmount` will contain the EUR amount that will be settled on your account._ - -##### Create fully integrated iDEAL payments ##### -To fully integrate iDEAL payments on your website, follow these additional steps: - -1. Retrieve the list of issuers (banks) that support iDEAL. - -```php -$method = $mollie->methods->get(\Mollie\Api\Types\PaymentMethod::IDEAL, ["include" => "issuers"]); -``` - -Use the `$method->issuers` list to let the customer pick their preferred issuer. - -_`$method->issuers` will be a list of objects. Use the property `$id` of this object in the - API call, and the property `$name` for displaying the issuer to your customer._ - -2. Create a payment with the selected issuer: - -```php -$payment = $mollie->payments->create([ - "amount" => [ - "currency" => "EUR", - "value" => "10.00" - ], - "description" => "My first API payment", - "redirectUrl" => "https://webshop.example.org/order/12345/", - "webhookUrl" => "https://webshop.example.org/mollie-webhook/", - "method" => \Mollie\Api\Types\PaymentMethod::IDEAL, - "issuer" => $selectedIssuerId, // e.g. "ideal_INGBNL2A" -]); -``` - -_The `_links` property of the `$payment` object will contain an object `checkout` with a `href` property, which is a URL that points directly to the online banking environment of the selected issuer. -A short way of retrieving this URL can be achieved by using the `$payment->getCheckoutUrl()`._ - -For a more in-depth example, see [Example - iDEAL payment](https://github.com/mollie/mollie-api-php/blob/master/examples/payments/create-ideal-payment.php). - -#### Retrieving Payments #### -**[Retrieve Payment Documentation](https://docs.mollie.com/reference/v2/payments-api/get-payment)** - -We can use the `$payment->id` to retrieve a payment and check if the payment `isPaid`. - -```php -$payment = $mollie->payments->get($payment->id); - -if ($payment->isPaid()) -{ - echo "Payment received."; -} -``` - -Or retrieve a collection of payments. - -```php -$payments = $mollie->payments->page(); -``` - -For an extensive example of listing payments with the details and status, see [Example - List Payments](https://github.com/mollie/mollie-api-php/blob/master/examples/payments/list-payments.php). +## Documentation +For an in-depth understanding of our API, please explore the [Mollie Developer Portal](https://www.mollie.com/developers). Our API documentation is available in English. -#### Refunding payments #### -**[Refund Payment Documentation](https://docs.mollie.com/reference/v2/refunds-api/create-payment-refund)** +For detailed documentation about using this PHP client, see the following guides: -Our API provides support for refunding payments. It's important to note that there is no confirmation step, and all refunds are immediate and final. Refunds are available for all payment methods except for paysafecard and gift cards. +- [Endpoint Collections](docs/endpoint-collections.md) - Learn how to interact with all available API endpoints. +- [HTTP Adapters](docs/http-adapters.md) - Information on customizing HTTP communication. +- [Idempotency](docs/idempotency.md) - Best practices and setup for idempotent requests. +- [Payments](docs/payments.md) - Comprehensive guide on handling payments. +- [Requests](docs/requests.md) - Overview and usage of request objects in the API client. +- [Responses](docs/responses.md) - Handling and understanding responses from the API. +- [Testing](docs/testing.md) - Guidelines for testing with the Mollie API client. -```php -$payment = $mollie->payments->get($payment->id); - -// Refund € 2 of this payment -$refund = $payment->refund([ - "amount" => [ - "currency" => "EUR", - "value" => "2.00" - ] -]); -``` +These guides provide in-depth explanations and examples for advanced usage of the client. -#### Payment webhook #### -When the payment status changes, the `webhookUrl` you specified during payment creation will be called. You can use the `id` from the POST parameters to check the status and take appropriate actions. For more details, refer to [Example - Webhook](https://github.com/mollie/mollie-api-php/blob/master/examples/payments/webhook.php). +## Examples -For a working example, see [Example - Refund payment](https://github.com/mollie/mollie-api-php/blob/master/examples/payments/refund-payment.php). +The Mollie API client comes with a variety of examples to help you understand how to implement various API features. These examples are a great resource for learning how to integrate Mollie payments into your application. -### Enabling debug mode ### +Here are some of the key examples included: -When troubleshooting, it can be highly beneficial to have access to the submitted request within the `ApiException`. To safeguard against inadvertently exposing sensitive request data in your local application logs, the debugging feature is initially turned off. +- **Create Payment**: Demonstrates how to create a new payment. + - [Create a simple payment](examples/payments/create-payment.php) + - [Create an iDEAL payment](examples/payments/create-ideal-payment.php) + - [Create a payment with manual capture](examples/payments/create-capturable-payment.php) -To enable debugging and inspect the request: +- **Manage Customers**: Shows how to manage customers in your Mollie account. + - [Create a customer](examples/customers/create-customer.php) + - [Update a customer](examples/customers/update-customer.php) + - [Delete a customer](examples/customers/delete-customer.php) -```php -/** @var $mollie \Mollie\Api\MollieApiClient */ -$mollie->enableDebugging(); - -try { - $mollie->payments->get('tr_12345678'); -} catch (\Mollie\Api\Exceptions\ApiException $exception) { - $request = $exception->getRequest(); -} -``` +- **Subscriptions and Recurring Payments**: + - [Create a customer for recurring payments](examples/customers/create-customer-first-payment.php) + - [Create a recurring payment](examples/customers/create-customer-recurring-payment.php) -If you are recording instances of `ApiException`, the request details will be included in the logs. It is vital to ensure that no sensitive information is retained within these logs and to perform cleanup after debugging is complete. +For a full list of examples, please refer to the [examples directory](examples/). -To disable debugging again: +These examples are designed to be run in a safe testing environment. Make sure to use your test API keys and review each example's code before integrating it into your production environment. -```php -/** @var $mollie \Mollie\Api\MollieApiClient */ -$mollie->disableDebugging(); -``` +## Upgrading -Please note that debugging is only available when using the default Guzzle http adapter (`Guzzle6And7MollieHttpAdapter`). - -## API documentation ## -For an in-depth understanding of our API, please explore the [Mollie Developer Portal](https://www.mollie.com/developers). Our API documentation is available in English. +Please see [UPGRADING](UPGRADING.md) for details. ## Contributing to Our API Client ## Would you like to contribute to improving our API client? We welcome [pull requests](https://github.com/mollie/mollie-api-php/pulls?utf8=%E2%9C%93&q=is%3Apr). But, if you're interested in contributing to a technology-focused organization, Mollie is actively recruiting developers and system engineers. Discover our current [job openings](https://jobs.mollie.com/) or [reach out](mailto:personeel@mollie.com). diff --git a/UPGRADING.md b/UPGRADING.md new file mode 100644 index 000000000..4b9363491 --- /dev/null +++ b/UPGRADING.md @@ -0,0 +1,277 @@ +- [x] remove `OrganizationsCollection` and change parent class of `OrganizationEndpoint` to `EndpointAbstract` +- [x] remove `RouteCollection` and change parent class of `PaymentRouteEndpoint` to `EndpointAbstract` +- [ ] check naming methods and standardise them (e.g. `SettlementCaptureEndpoint@pageForId()` vs `PaymentChargbackEndpoint@listForId()`) +- [x] Type cast embedded resources. I.e. when including refunds and chargebacks on a GET payment request, the refunds and chargebacks are not type cast. +- [x] [PSR-18 Support](https://github.com/mollie/mollie-api-php/issues/703) +- [ ] ~~rename `MethodEndpoint@all()` or remove it to avoid confusion over `allAvailable()` vs `all()`~~ -> marked as deprecated +- [x] Add Type: CaptureMode +- [x] change return types on resources +- [ ] check resources that have embedded resources whether they need to call an endpoint to provide the data +- [ ] check endpoint calls in resources for unnecessary code + - [x] check if we can add a trait for getPresetOptions and withPresetOptions +- [x] removed deprecated OrderStatus::REFUNDED OrderLineStatus::REFUNDED +- [x] refactored collections for easier usage +- [ ] update documentation +- [ ] add sessions endpoint (added by @sandervanhooft) +--- +Posting this here for now. For the upgrading steps I have created a separate file. For the changelog we don't have any file yet. May be worth to start a `CHANGELOG.md` file which is automatically filled via a github action from the release notes. + +# Upgrading +## From v2 to v3 +### Removed unused Collections +This change should not have any impact on your code, but if you have a type hint for any of the following classes, make sure to remove it +- `Mollie\Api\Resources\OrganizationCollection` +- `Mollie\Api\Resources\RouteCollection` + +### Removed deprecations +The following was removed due to a deprecation +- `Mollie\Api\Types\OrderStatus::REFUNDED` +- `Mollie\Api\Types\OrderLineStatus::REFUNDED` +- all Orders related endpoints + - properties starting with `orders` prefix or related to any `Order*Endpoint` + - `orderPayments` + - `orderRefunds` + - `orderLines` + - `orderPayments` + - Shipments endpoint (all properties prefixed with `shipments` / `Shipment*Endpoint`) + +### Removed non-valid method params +**Mollie\Api\EndpointCollection\CustomerPaymentsEndpointCollection** +- `createFor()` and `createForId()` removed third argument `$filters` + +**Mollie\Api\EndpointCollection\InvoiceEndpointCollection** +- `get()` removed second argument `$parameters` + +**Mollie\Api\EndpointCollection\MandateEndpointCollection** +- `createFor()` and `createForId()` removed third argument `$filters` + +**Mollie\Api\EndpointCollection\PaymentCaptureEndpointCollection** +- `createFor()` and `createForId()` removed third argument `$filters` + +### Removed methods +**Mollie\Api\EndpointCollection\InvoiceEndpointCollection** +- `all()` was removed -> use `page()` instead + +### change of function names +Accross the codebase we have had inconsistent namings like `listFor()` as well as `pageFor()` and `page()`. Those have been standardized. Endpoints that return a paginated response use the `page*()` naming while non-paginated endpoints use `list*()`. The following method names were changed. + +**Mollie\Api\EndpointCollection\BalanceTransactionEndpointCollection** +- `balanceTransactions->listFor()` into `balanceTransactions->pageFor()` +- `balanceTransactions->listForId()` into `balanceTransactions->pageForId()` + +**Mollie\Api\EndpointCollection\CustomerPaymentsEndpointCollection** +- `customerPayments->listFor()` into `customerPayments->pageFor()` +- `customerPayments->listForId()` into `customerPayments->pageForId()` + +**Mollie\Api\EndpointCollection\MandateEndpointCollection** +- `mandates->listFor()` into `mandates->pageFor()` +- `mandates->listForId()` into `mandates->pageForId()` + +**Mollie\Api\EndpointCollection\PaymentRefundEndpointCollection** +- `paymentRefunds->listFor()` into `paymentRefunds->pageFor()` +- `paymentRefunds->listForId()` into `paymentRefunds->pageForId()` + +**Mollie\Api\EndpointCollection\MethodEndpointCollection** +- `methods->allAvailable()` has been renamed into `methods->all()` now returns all available methods (both enabled and disabled) - previously returned only all enabled methods +- former `methods->all()` has been renamed to `methods->allEnabled()` +- `methods->allActive()` is deprecated + +The reasoning behind this change is to make the method names more intuitive: +- `all()` returns ALL methods (both enabled and disabled) +- `allEnabled()` returns only the enabled methods (previously called `allActive()`) +- The `allActive()` method is deprecated and will be removed in v4 + +**Mollie\Api\EndpointCollection\OnboardingEndpointCollection** +- `get()` was changed into `status()` +- depricated `submit()` and `create()` were removed -> use `ClientLinkEndpointCollection@create()` instead + +**Mollie\Api\EndpointCollection\PaymentCaptureEndpointCollection** +- `paymentCaptures->listFor()` into `paymentCaptures->pageFor()` +- `paymentCaptures->listForId()` into `paymentCaptures->pageForId()` + +**Mollie\Api\EndpointCollection\PaymentChargebackEndpointCollection** +- `listFor()` into `pageFor()` +- `listForId()` into `pageForId()` + +**Mollie\Api\EndpointCollection\PaymentRefundEndpointCollection** +- `pageFor(Payment $payment, array $parameters = [])` changed to `pageFor(Payment $payment, ?string $from = null, ?int $limit = null, array $filters = [])` +- `pageForId(string $paymentId, array $parameters = [])` changed to `pageForId(string $paymentId, ?string $from = null, ?int $limit = null, array $filters = [])` + +**Mollie\Api\EndpointCollection\SubscriptionEndpointCollection** +- `listFor` changed to `pageFor` +- `listForId` changed to `pageForId` +- `page` which previously returned all subscriptions, was renamed into `allFor` +- `allForId` and `iteratorForAll` were added to return all subscriptions + +### Renamed methods +**Mollie\Api\EndpointCollection\PermissionEndpointCollection** +- `all()` was renamed to `list()` to maintain consistency with other non-paginated endpoints + +### Removed non-valid method params +**Mollie\Api\EndpointCollection\PermissionEndpointCollection** +- `get()` second argument changed from `array $parameters` to `array|bool $testmode` to match API documentation + +# Changelog +### Type cast embeded Resources +In previous versions resources requested via `embed` param on requests like [get-payment](https://docs.mollie.com/reference/get-payment) were not casted into their respective collection or resource classes. Starting with this version all embeded resources are typecasted. + +```php +$payment = $mollie->payments->get('...', ['embed' => ['refunds']]); + +$this->assertInstanceOf(RefundCollection::class, $payment->_embedded->refunds); +``` + +### Added CaptureMode +A new `Mollie\Api\Types\CaptureMode` class which can be used when using on the [create-payment request](https://docs.mollie.com/reference/create-payment) (s. *captureMode*) when using the [capture feature](https://docs.mollie.com/reference/create-capture). + +### PSR-18 Support +We added a new HTTP-adapter which supports PSR-18. The following example demonstrates on how to use the new adapter. + +**Note**: The example uses `nyholm/psr7` to get all necessary factories required. You can use the same factories by running `composer require nyholm/psr7`. + +```php +use Mollie\Api\MollieApiClient; +use Psr\Http\Client\ClientInterface; +use Nyholm\Psr7\Factory\Psr17Factory; +use GuzzleHttp\Client as GuzzleClient; +use Psr\Http\Message\RequestFactoryInterface; +use Psr\Http\Message\StreamFactoryInterface; +use Mollie\Api\HttpAdapter\PSR18MollieHttpAdapter; + +// Create instances of the required classes +$httpClient = new GuzzleClient(); // Instance of ClientInterface +$requestFactory = new Psr17Factory(); // Instance of RequestFactoryInterface +$streamFactory = new Psr17Factory(); // Instance of StreamFactoryInterface + +// Instantiate the PSR18MollieHttpAdapter +$mollieHttpAdapter = new PSR18MollieHttpAdapter( + $httpClient, + $requestFactory, + $streamFactory +); + +$client = new MollieApiClient($mollieHttpAdapter); + +$client->setApiKey("test_qM2fCcTADeP6m87E5yFbnzfcUGpEDb"); +$client->payments->page(); +``` + +### Added Collection Methods +Two new collection methods were added which can be used to simplify interacting with collection resources. + +- `contains(callable $callback): bool` +- `filter(callable $callback): static` + +### Testmode is automatically removed.. +..If an API key is used as authentication. + +Say Goodby to the annoying `[...]. Try switching live / test API keys.` + +### Requests, Payloads and Queries +The new version can be used as before **without any changes to the codebase** (except the few mentioned above). The underlying codebase was changed drastically to allow a few improvements. There are now 3 different ways to interact with the client. + +#### The old way +Just as you used to... Pass in arrays of data and receive your Resource/ResourceCollection. + +```php +// old way of creating a payment +$payment = $mollie->payments->create([ + "amount" => [ + "currency" => "EUR", + "value" => "10.00" + ], + "description" => "My first API payment", + "redirectUrl" => "https://webshop.example.org/order/12345/", + "webhookUrl" => "https://webshop.example.org/mollie-webhook/", +]); +``` + +#### Slightly improved +With this approach you can use new Objects and therefore actually know what data is required to pass into the method, but you can still using the old way of calling the request. + +```php +// improved +use Mollie\Api\Http\Data\Money; +use Mollie\Api\Http\Data\CreatePaymentPayload; + +$payload = new CreatePaymentPayload( + description: 'My first API payment', + amount: new Money('EUR', '10.00'), + redirectUrl: 'https://webshop.example.org/order/12345/', + webhookUrl: 'https://webshop.example.org/mollie-webhook/' +); + +$payment = $mollie->payments->create($payload); +``` +#### This is the way! +Finally, the new way of interacting with the client: +1. create your payload +2. pass it into your request +3. send it +4. inspect response +4b. receive your Resoure/ResourceCollection + +```php +// newest ;-) +use Mollie\Api\Http\Data\Money; +use Mollie\Api\Http\Data\CreatePaymentPayload; +use Mollie\Api\Http\Requests\CreatePaymentRequest; + +$payload = new CreatePaymentPayload( + description: 'My first API payment', + amount: new Money('EUR', '10.00'), + redirectUrl: 'https://webshop.example.org/order/12345/', + webhookUrl: 'https://webshop.example.org/mollie-webhook/' +); + +$response = $mollie->send($payload); + +$payment = $response->toResource(); +$jsonData = $response->json(); +$status = $response->status(); +``` + +With this you get a `Response` and can also inspect its status, body or any other payload. If you want to use the `$client->send()` method but don't want to call the `->toResource()` method to receive your Resource, you can simply call `MollieApiClient::shouldAutoHydrate()`. + +--- + +## Some Context... +..on how the new request cycle works + + +### Added contractId parameter for Method Issuers +The `enable()` method on the `MethodIssuerEndpointCollection` now supports an optional `contractId` parameter when enabling voucher issuers. This parameter can be used when an intermediary party (contractor) is involved([1](https://docs.mollie.com/reference/enable-method-issuer)). + +```php +// Enable a method issuer with a contract ID +$issuer = $mollie->methodIssuers->enable( + profileId: 'pfl_...', + methodId: 'voucher', + issuerId: 'issuer_id', + contractId: 'contract_123' // Optional parameter +); +``` + +The contract ID can be updated as long as it hasn't been approved yet by repeating the API call with a different contract ID. + +### Added optional testmode parameter +The following methods now accept an optional `testmode` parameter: + +**Mollie\Api\EndpointCollection\PaymentLinkEndpointCollection** +- `get(string $paymentLinkId, ?bool $testmode = null)` +- `update(string $paymentLinkId, $payload = [], ?bool $testmode = null)` +- `delete(string $paymentLinkId, ?bool $testmode = null)` + +This parameter can be used when working with organization-level credentials such as OAuth access tokens to specify whether the operation should be performed in test mode. For API key credentials, this parameter can be omitted as the mode is determined by the key type. + +```php +// Example with testmode parameter +$paymentLink = $mollie->paymentLinks->get('pl_...', testmode: true); +$paymentLink = $mollie->paymentLinks->update('pl_...', ['description' => 'Updated'], testmode: true); +$mollie->paymentLinks->delete('pl_...', testmode: true); +``` + +--- + +- removed `STATUS` prefix on all type constants +- collection constructors changed, they don't include the counted items anymore diff --git a/composer.json b/composer.json index 04def5417..46cd65ccc 100644 --- a/composer.json +++ b/composer.json @@ -47,18 +47,21 @@ } ], "require": { - "php": "^7.2|^8.0", + "php": "^7.4|^8.0", "ext-curl": "*", "ext-json": "*", "ext-openssl": "*", - "composer/ca-bundle": "^1.2" + "composer/ca-bundle": "^1.4", + "nyholm/psr7": "^1.8", + "psr/http-factory": "^1.1", + "psr/http-message": "^2.0" }, "require-dev": { - "eloquent/liberator": "^2.0||^3.0", - "friendsofphp/php-cs-fixer": "^3.0", - "guzzlehttp/guzzle": "^6.3 || ^7.0", - "phpstan/phpstan": "^1.12", - "phpunit/phpunit": "^8.5 || ^9.5" + "brianium/paratest": "^6.11", + "guzzlehttp/guzzle": "^7.6", + "laravel/pint": "^1.18", + "phpstan/phpstan": "^2.0", + "phpunit/phpunit": "^9.6" }, "suggest": { "mollie/oauth2-mollie-php": "Use OAuth to authenticate with the Mollie API. This is needed for some endpoints. Visit https://docs.mollie.com/ for more information." @@ -79,6 +82,6 @@ }, "scripts": { "test": "./vendor/bin/phpunit tests", - "format": "./vendor/bin/php-cs-fixer fix --allow-risky=yes" + "format": "./vendor/bin/pint" } } diff --git a/docs/endpoint-collections.md b/docs/endpoint-collections.md new file mode 100644 index 000000000..c1f326a9a --- /dev/null +++ b/docs/endpoint-collections.md @@ -0,0 +1,778 @@ +# Introduction +Endpoint collections provide a fluent interface for interacting with Mollie's API. Each collection manages specific resource types like payments, customers, and subscriptions, offering methods to create, retrieve, update, and delete these resources. + +## Setup + +1. **Initialize the Mollie Client:** + +```php +$mollie = new \Mollie\Api\MollieApiClient(); +$mollie->setApiKey("test_*************************"); +``` + +2. **Access Endpoints via the Client:** +```php +// Payments endpoint +$mollie->payments->... + +// Customers endpoint +$mollie->customers->... + +// Other endpoints +$mollie->balances->... +$mollie->orders->... +``` + +3. **Call methods** + +**Simple: Using arrays** +This approach is direct but provides less type safety: +```php +$payment = $mollie->payments->create([ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '10.00' + ], + 'description' => 'My first API payment' +]); +``` + +**Advanced: Using typed payloads/queries** +This approach provides full IDE support and type safety: +```php +use Mollie\Api\Http\Data\Money; +use Mollie\Api\Http\Data\CreatePaymentPayload; + +$payment = $mollie->payments->create( + new CreatePaymentPayload( + description: 'My first API payment', + amount: new Money('EUR', '10.00') + ) +); +``` + +If you have an array and need to interact with the payload or query, you can use a dedicated factory to convert the array into a typed class. + +use Mollie\Api\Http\Data\Money; +use Mollie\Api\Factories\CreatePaymentPayloadFactory; + +// Fully untyped data +$createPaymentPayload = CreatePaymentPayloadFactory::new([ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '10.00' + ], + 'description' => 'My first API payment' +]); + +// Partially untyped +$createPaymentPayload = CreatePaymentPayloadFactory::new([ + 'amount' => new Money('EUR', '10.00'), + 'description' => 'My first API payment' +]); + +// Access payload +$createPaymentPayload->amount->... +``` + +This approach allows you to seamlessly convert arrays into typed objects, providing better IDE support and type safety while working with your data. + +# Available Endpoints + +## Balances + +[Official Documentation](https://docs.mollie.com/reference/v2/balances-api/get-balance) + +**Available Queries:** +- `GetPaginatedBalanceQuery` - For listing balances with pagination + +### Balance Information + +```php +// Get primary balance +$balance = $mollie->balances->primary(); + +// Get specific balance +$balance = $mollie->balances->get('bal_12345'); + +// List balances +$balances = $mollie->balances->page(); +``` + +## Balance Reports + +[Official Documentation](https://docs.mollie.com/reference/v2/balance-reports-api/get-balance-report) + +**Available Queries:** +- `GetBalanceReportQuery` - For retrieving balance reports + +### Balance Report Details + +```php +// Get report for specific balance +$report = $mollie->balanceReports->getForId('bal_12345', [ + 'from' => '2024-01-01', + 'until' => '2024-01-31', + 'grouping' => 'transaction-categories' +]); +``` + +## Balance Transactions + +[Official Documentation](https://docs.mollie.com/reference/v2/balance-transactions-api/list-balance-transactions) + +**Available Queries:** +- `GetPaginatedBalanceQuery` - For listing balance transactions with pagination + +### Balance Transaction Management + +```php +// Get transactions for a balance +$transactions = $mollie->balanceTransactions->pageFor($balance); + +// Use iterator for all transactions +foreach ($mollie->balanceTransactions->iteratorFor($balance) as $transaction) { + echo $transaction->id; +} +``` + +## Chargebacks + +[Official Documentation](https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback) + +**Available Queries:** +- `GetPaginatedChargebacksQuery` - For listing chargebacks with pagination + +### Chargeback Management + +```php +// Get all chargebacks +$chargebacks = $mollie->chargebacks->page(); + +// Use iterator for all chargebacks +foreach ($mollie->chargebacks->iterator() as $chargeback) { + echo $chargeback->id; +} +``` + +## Clients + +[Official Documentation](https://docs.mollie.com/reference/v2/clients-api/get-client) + +**Available Queries:** +- `GetClientQuery` - For retrieving client details + +### Client Management + +```php +// Get a specific client +$client = $mollie->clients->get('org_12345678', [ + 'testmode' => true +]); + +// List all clients +$clients = $mollie->clients->page( + from: 'org_12345678', + limit: 50 +); +``` + +## Customers + +[Official Documentation](https://docs.mollie.com/reference/v2/customers-api/create-customer) + +**Available Payloads:** +- `CreateCustomerPayload` - For creating new customers +- `UpdateCustomerPayload` - For updating existing customers + +### Customer Management + +```php +// Create a customer +$customer = $mollie->customers->create([ + 'name' => 'John Doe', + 'email' => 'john@example.org', +]); + +// Get a customer +$customer = $mollie->customers->get('cst_8wmqcHMN4U'); + +// Update a customer +$customer = $mollie->customers->update('cst_8wmqcHMN4U', [ + 'name' => 'Updated Name' +]); + +// Delete a customer +$mollie->customers->delete('cst_8wmqcHMN4U'); + +// List customers +$customers = $mollie->customers->page(); +``` + +## Invoices + +[Official Documentation](https://docs.mollie.com/reference/v2/invoices-api/get-invoice) + +**Available Queries:** +- `GetPaginatedInvoiceQuery` - For listing invoices with pagination + +### Invoice Management + +```php +// Get a specific invoice +$invoice = $mollie->invoices->get('inv_xBEbP9rvAq'); + +// List all invoices +$invoices = $mollie->invoices->page( + from: 'inv_xBEbP9rvAq', + limit: 50 +); +``` + +## Mandates + +[Official Documentation](https://docs.mollie.com/reference/v2/mandates-api/create-mandate) + +**Available Payloads:** +- `CreateMandatePayload` - For creating new mandates + +### Mandate Management + +```php +// Create a mandate for a customer +$mandate = $mollie->mandates->createFor($customer, [ + 'method' => \Mollie\Api\Types\PaymentMethod::DIRECTDEBIT, + 'consumerName' => 'John Doe', + 'consumerAccount' => 'NL55INGB0000000000', + 'consumerBic' => 'INGBNL2A', + 'signatureDate' => '2024-01-01', + 'mandateReference' => 'YOUR-COMPANY-MD13804' +]); + +// Get a mandate +$mandate = $mollie->mandates->getFor($customer, 'mdt_h3gAaD5zP'); + +// Revoke a mandate +$mollie->mandates->revokeFor($customer, 'mdt_h3gAaD5zP'); + +// List mandates +$mandates = $mollie->mandates->pageFor($customer); +``` + +## Methods + +[Official Documentation](https://docs.mollie.com/reference/v2/methods-api/get-method) + +**Available Queries:** +- `GetPaymentMethodQuery` - For retrieving method details +- `GetAllMethodsQuery` - For listing all available methods +- `GetEnabledPaymentMethodsQuery` - For listing enabled methods + +### Payment Methods + +```php +// Get a method +$method = $mollie->methods->get(\Mollie\Api\Types\PaymentMethod::IDEAL); + +// List all methods +$methods = $mollie->methods->all(); + +// List enabled methods +$methods = $mollie->methods->allEnabled([ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '100.00' + ] +]); +``` + +### Method Issuers + +```php +// Enable an issuer +$issuer = $mollie->methodIssuers->enable( + 'pfl_v9hTwCvYqw', + \Mollie\Api\Types\PaymentMethod::IDEAL, + 'ideal_INGBNL2A' +); + +// Disable an issuer +$mollie->methodIssuers->disable( + 'pfl_v9hTwCvYqw', + \Mollie\Api\Types\PaymentMethod::IDEAL, + 'ideal_INGBNL2A' +); +``` + +## Onboarding + +[Official Documentation](https://docs.mollie.com/reference/v2/onboarding-api/get-onboarding-status) + +**Available Queries:** +- `GetOnboardingStatusQuery` - For retrieving onboarding status + +### Onboarding Management + +```php +// Get onboarding status +$onboarding = $mollie->onboarding->status(); +``` + +## Organizations + +[Official Documentation](https://docs.mollie.com/reference/v2/organizations-api/get-organization) + +**Available Queries:** +- `GetOrganizationQuery` - For retrieving organization details + +### Organization Management + +```php +// Get an organization +$organization = $mollie->organizations->get('org_12345678'); + +// Get current organization +$organization = $mollie->organizations->current(); + +// Get partner status +$partner = $mollie->organizations->partnerStatus(); +``` + +## Permissions + +[Official Documentation](https://docs.mollie.com/reference/v2/permissions-api/get-permission) + +**Available Queries:** +- `GetPermissionQuery` - For retrieving permission details + +### Permission Management + +```php +// Get a permission +$permission = $mollie->permissions->get('payments.read'); + +// List all permissions +$permissions = $mollie->permissions->list(); +``` + +## Payments + +[Official Documentation](https://docs.mollie.com/reference/v2/payments-api/create-payment) + +**Available Payloads:** +- `CreatePaymentPayload` - For creating new payments +- `UpdatePaymentPayload` - For updating existing payments + +**Available Queries:** +- `GetPaymentQuery` - For retrieving payments with optional embeds +- `GetPaginatedPaymentsQuery` - For listing payments with pagination + +### Payment Management + +```php +// Create a payment using typed payload +use Mollie\Api\Http\Data\Money; +use Mollie\Api\Http\Data\CreatePaymentPayload; + +$payload = new CreatePaymentPayload( + description: 'Order #12345', + amount: new Money('EUR', '10.00'), + redirectUrl: 'https://webshop.example.org/order/12345/', + webhookUrl: 'https://webshop.example.org/mollie-webhook/' +); + +$payment = $mollie->payments->create($payload); + +// Get a payment +$payment = $mollie->payments->get('tr_7UhSN1zuXS'); + +// Update a payment +$payment = $mollie->payments->update('tr_7UhSN1zuXS', [ + 'description' => 'Updated description' +]); + +// Cancel a payment +$mollie->payments->cancel('tr_7UhSN1zuXS'); + +// List payments +$payments = $mollie->payments->page(); +``` + +### Payment Links + +[Official Documentation](https://docs.mollie.com/reference/v2/payment-links-api/create-payment-link) + +**Available Payloads:** +- `CreatePaymentLinkPayload` - For creating payment links +- `UpdatePaymentLinkPayload` - For updating payment links + +### Payment Captures + +[Official Documentation](https://docs.mollie.com/reference/v2/captures-api/get-capture) + +**Available Payloads:** +- `CreatePaymentCapturePayload` - For creating captures + +**Available Queries:** +- `GetPaymentCaptureQuery` - For retrieving capture details +- `GetPaginatedPaymentCapturesQuery` - For listing captures + +### Payment Chargebacks + +```php +// Get a chargeback +$chargeback = $mollie->paymentChargebacks->getFor($payment, 'chb_n9z0tp'); + +// List chargebacks for payment +$chargebacks = $mollie->paymentChargebacks->pageFor($payment); +``` + +### Payment Routes + +```php +// Update release date for a route +$route = $mollie->paymentRoutes->updateReleaseDateFor( + $payment, + 'rt_abc123', + '2024-01-01' +); +``` + +## Profiles + +[Official Documentation](https://docs.mollie.com/reference/v2/profiles-api/create-profile) + +**Available Payloads:** +- `CreateProfilePayload` - For creating new profiles + +**Available Factories:** +- `ProfileFactory` - For creating profile instances + +### Profile Management + +```php +// Create a profile +$profile = $mollie->profiles->create(new CreateProfilePayload( + 'My Test Profile', + 'https://example.org', + 'info@example.org', + '+31612345678', + 'test' +)); + +// Get a profile +$profile = $mollie->profiles->get('pfl_v9hTwCvYqw'); + +// Get current profile +$profile = $mollie->profiles->getCurrent(); + +// Update a profile +$profile = $mollie->profiles->update('pfl_v9hTwCvYqw', [ + 'name' => 'Updated Profile Name' +]); + +// Delete a profile +$mollie->profiles->delete('pfl_v9hTwCvYqw'); + +// List profiles +$profiles = $mollie->profiles->page(); +``` + +### Profile Methods + +```php +// Enable a method +$method = $mollie->profileMethods->enable( + 'pfl_v9hTwCvYqw', + \Mollie\Api\Types\PaymentMethod::IDEAL +); + +// Disable a method +$mollie->profileMethods->disable( + 'pfl_v9hTwCvYqw', + \Mollie\Api\Types\PaymentMethod::IDEAL +); +``` + +## Refunds + +[Official Documentation](https://docs.mollie.com/reference/v2/refunds-api/create-refund) + +**Available Payloads:** +- `CreateRefundPaymentPayload` - For creating refunds on payments +- `CreateRefundOrderPayload` - For creating refunds on orders + +**Available Queries:** +- `GetPaginatedRefundsQuery` - For listing refunds with pagination + +### Refund Management + +```php +// Create a refund for a payment +$refund = $mollie->refunds->createForPayment($paymentId, [ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '15.00' + ], + 'description' => 'Refund for returned item' +]); + +// List refunds +$refunds = $mollie->refunds->page(); +``` + +## Sales Invoices + +[Official Documentation TBA] + +**Available Payloads:** +- `CreateSalesInvoicePayload` - For creating sales invoices +- `UpdateSalesInvoicePayload` - For updating existing sales invoices + +**Available Queries:** +- `GetPaginatedSalesInvoiceQuery` - For listing sales invoices with pagination + +### Sales Invoice Management + +```php +use Mollie\Api\Types\VatMode; +use Mollie\Api\Types\VatScheme; +use Mollie\Api\Types\PaymentTerm; +use Mollie\Api\Types\RecipientType; +use Mollie\Api\Types\RecipientType; +use Mollie\Api\Types\SalesInvoiceStatus; + +// Create a sales invoice +$salesInvoice = $mollie->salesInvoices->create([ + 'currency' => 'EUR', + 'status' => SalesInvoiceStatus::DRAFT, + 'vatScheme' => VatScheme::STANDARD, + 'vatMode' => VatMode::INCLUSIVE, + 'paymentTerm' => PaymentTerm::DAYS_30, + 'recipientIdentifier' => 'XXXXX', + 'recipient' => [ + 'type' => RecipientType::CONSUMER, + 'email' => 'darth@vader.deathstar', + 'streetAndNumber' => 'Sample Street 12b', + 'postalCode' => '2000 AA', + 'city' => 'Amsterdam', + 'country' => 'NL', + 'locale' => 'nl_NL' + ], + 'lines' => [ + [ + 'description' => 'Monthly subscription fee', + 'quantity' => 1, + 'vatRate' => '21', + 'unitPrice' => [ + 'currency' => 'EUR', + 'value' => '10,00' + ] + ] + ] +]); + +// Get a sales invoice +$salesInvoice = $mollie->salesInvoices->get('invoice_12345'); + +// Update a sales invoice +$salesInvoice = $mollie->salesInvoices->update('invoice_12345', [ + 'description' => 'Updated description' +]); + +// Delete a sales invoice +$mollie->salesInvoices->delete('invoice_12345'); + +// List sales invoices +$salesInvoices = $mollie->salesInvoices->page(); +``` + +## Sessions + +[Official Documentation](https://docs.mollie.com/reference/v2/sessions-api/create-session) + +**Available Payloads:** +- `CreateSessionPayload` - For creating sessions + +**Available Queries:** +- `GetPaginatedSessionsQuery` - For listing sessions with pagination + +### Session Management + +```php +// Create a session +$session = $mollie->sessions->create([ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '100.00' + ], + 'description' => 'Session for service' +]); + +// Get a session +$session = $mollie->sessions->get('sessionId'); +``` + +## Settlements + +[Official Documentation](https://docs.mollie.com/reference/v2/settlements-api/get-settlement) + +**Available Queries:** +- `GetPaginatedSettlementsQuery` - For listing settlements with pagination + +### Settlement Management + +```php +// Get a settlement +$settlement = $mollie->settlements->get('settlementId'); + +// List settlements +$settlements = $mollie->settlements->page(); +``` + +### Settlement Captures + +```php +// Get captures for a settlement +$captures = $mollie->settlementCaptures->pageFor($settlement); + +// Use iterator +foreach ($mollie->settlementCaptures->iteratorFor($settlement) as $capture) { + echo $capture->id; +} +``` + +### Settlement Chargebacks + +```php +// List chargebacks for a settlement +$chargebacks = $mollie->settlementChargebacks->pageFor($settlement); + +// Use iterator +foreach ($mollie->settlementChargebacks->iteratorFor($settlement) as $chargeback) { + echo $chargeback->id; +} +``` + +### Settlement Payments + +```php +// List payments in a settlement +$payments = $mollie->settlementPayments->pageFor($settlement); + +// Use iterator +foreach ($mollie->settlementPayments->iteratorFor($settlement) as $payment) { + echo $payment->id; +} +``` + +## Subscriptions + +[Official Documentation](https://docs.mollie.com/reference/v2/subscriptions-api/create-subscription) + +**Available Payloads:** +- `CreateSubscriptionPayload` - For creating subscriptions + +**Available Queries:** +- `GetAllPaginatedSubscriptionsQuery` - For listing all subscriptions + +### Subscription Management + +```php +// Create a subscription +$subscription = $mollie->subscriptions->createForCustomer('customerId', [ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '25.00' + ], + 'interval' => '1 month', + 'description' => 'Monthly subscription' +]); + +// List subscriptions +$subscriptions = $mollie->subscriptions->pageForCustomer('customerId'); +``` + +## Terminals + +[Official Documentation](https://docs.mollie.com/reference/v2/terminals-api/get-terminal) + +**Available Queries:** +- `GetPaginatedTerminalsQuery` - For listing terminals with pagination + +### Terminal Management + +```php +// Get a terminal +$terminal = $mollie->terminals->get('terminalId'); + +// List terminals +$terminals = $mollie->terminals->page(); +``` + +## Wallets + +[Official Documentation](https://docs.mollie.com/reference/v2/wallets-api/request-apple-pay-payment-session) + +**Available Payloads:** +- `RequestApplePayPaymentSessionPayload` - For requesting Apple Pay payment sessions + +### Wallet Management + +```php +// Request an Apple Pay payment session +$session = $mollie->wallets->requestApplePayPaymentSession([ + 'domainName' => 'example.com', + 'validationUrl' => 'https://apple-pay-gateway.apple.com/paymentservices/startSession' +]); +``` + +## Common Patterns + +### Pagination + +Most list methods support pagination: + +```php +// Get first page +$payments = $mollie->payments->page(); + +// Get specific page +$payments = $mollie->payments->page( + from: 'tr_7UhSN1zuXS', // Start from this ID + limit: 50 // Items per page +); + +// Get all items using iterator +foreach ($mollie->payments->iterator() as $payment) { + echo $payment->id; +} +``` + +### Error Handling + +Handle errors using `ApiException`: + +```php +try { + $payment = $mollie->payments->get('tr_xxx'); +} catch (\Mollie\Api\Exceptions\ApiException $e) { + echo "API call failed: {$e->getMessage()}"; +} +``` + +## Common Data Types + +- `Money` - For handling currency amounts +- `Metadata` - For handling custom metadata +- `DataCollection` - For handling collections of data +- `Data` - Base class for payload/query objects + +## Factories + +**Query Factories:** +- `PaginatedQueryFactory` - For creating paginated queries +- `SortablePaginatedQueryFactory` - For creating sortable paginated queries + +**Payload Factories:** +- `CreatePaymentPayloadFactory` - For creating payment payloads diff --git a/docs/http-adapters.md b/docs/http-adapters.md new file mode 100644 index 000000000..46d05aa25 --- /dev/null +++ b/docs/http-adapters.md @@ -0,0 +1,74 @@ +# HTTP Adapters + +## Overview + +An HTTP adapter is a component that manages the communication between your application and an API. It abstracts the details of making HTTP requests and handling responses, allowing you to use different HTTP clients (like Guzzle, cURL, or custom clients) interchangeably without changing the way you interact with the API. + +## MollieHttpAdapterPicker + +The `MollieHttpAdapterPicker` is responsible for selecting the appropriate HTTP adapter based on the environment or the provided HTTP client. If no client is specified in the `MollieApiClient` constructor, it picks a default adapter. + +### How It Works + +1. **No Client Specified**: If no client is provided, it checks if Guzzle is available and picks the appropriate version of the Guzzle adapter. +2. **Custom Client Provided**: If a custom client is provided and it implements the `HttpAdapterContract`, it is used directly. If it's a Guzzle client, it is wrapped in a `GuzzleMollieHttpAdapter`. +3. **Unrecognized Client**: Throws an `UnrecognizedClientException` if the client is not recognized. + +## Creating a Custom Adapter + +To create a custom HTTP adapter: +1. Implement HttpAdapterContract. +2. Use HasDefaultFactories Trait to simplify adapter implementation. + +```php +use Mollie\Api\Contracts\HttpAdapterContract; +use Mollie\Api\Traits\HasDefaultFactories; + +class MyCustomHttpAdapter implements HttpAdapterContract { + use HasDefaultFactories; + + public function sendRequest(PendingRequest $pendingRequest): Response { + // Implementation for sending HTTP request + } + + public function version(): ?string { + return 'my-custom-adapter/1.0'; + } +} +``` + +### Debugging + +When debugging mode is enabled, adapters remove sensitive information before they fire an exception. + +Adapters that support debugging must implement the `SupportsDebuggingContract`. This contract defines methods `enableDebugging()` and `disableDebugging()` to control debugging behavior. + +```php +use Mollie\Api\Contracts\SupportsDebuggingContract; + +class MyCustomHttpAdapter implements HttpAdapterContract, SupportsDebuggingContract { + // Implementation of debugging methods +} +``` + +## Available Adapters + +Out of the box, the Mollie API client provides several adapters: + +- **GuzzleMollieHttpAdapter**: Wraps a Guzzle HTTP client for sending requests. +- **CurlMollieHttpAdapter**: Uses cURL for sending HTTP requests. This is the default if Guzzle is not available. + +## Enabling Debugging + +Debugging can be enabled through the `HandlesDebugging` trait. This trait allows you to toggle debugging on the HTTP client, which is useful for development and troubleshooting. + +### How to Enable Debugging + +1. **Enable Debugging**: Call `enableDebugging()` on the Mollie API client instance. This sets the debugging mode on the underlying HTTP adapter, if it supports debugging. + +2. **Disable Debugging**: Call `disableDebugging()` to turn off debugging. + +```php +$mollieClient->enableDebugging(); +$mollieClient->disableDebugging(); +``` diff --git a/docs/idempotency.md b/docs/idempotency.md new file mode 100644 index 000000000..020afd3f8 --- /dev/null +++ b/docs/idempotency.md @@ -0,0 +1,57 @@ +# Idempotency + +## Overview + +Idempotency ensures that multiple identical requests to an API result in the same outcome without creating duplicate resources or effects. This is crucial for operations that involve financial transactions to prevent unintended charges or state changes. + +Mollie API supports idempotent requests for critical operations such as creating payments or refunds. This is automatically managed by the API client using the `ApplyIdempotencyKey` middleware. + +For more detailed information, refer to the [Mollie API Idempotency Documentation](https://docs.mollie.com/reference/api-idempotency). + +## Automatic Idempotency Key Handling + +The Mollie API client automatically handles idempotency for mutating requests (POST, PATCH, DELETE) through the `ApplyIdempotencyKey` middleware. This middleware checks if the request is a mutating type and applies an idempotency key if one is not already provided. + +### How It Works + +1. **Check Request Type**: The middleware checks if the request method is POST, PATCH, or DELETE. +2. **Apply Idempotency Key**: If the request is mutating, the middleware will: + - Use a custom idempotency key if provided. + - Otherwise, generate a key using the configured `IdempotencyKeyGenerator` if available. + - If no generator is set and no key is provided, no idempotency key is applied. + +### Customizing Idempotency Key + +You can customize how idempotency keys are generated or applied in several ways: + +- **Provide a Custom Key**: Manually set an idempotency key for a specific request. +- **Use a Custom Generator**: Implement the `IdempotencyKeyGeneratorContract` to provide a custom method of generating idempotency keys. + +#### Example: Setting a Custom Key + +```php +$mollie->setIdempotencyKey('your_custom_key_here'); +``` + +#### Example: Using a Custom Key Generator + +Implement your key generator: + +```php +class MyCustomKeyGenerator implements IdempotencyKeyGeneratorContract { + public function generate(): string { + return 'custom_' . bin2hex(random_bytes(10)); + } +} + +$mollie->setIdempotencyKeyGenerator(new MyCustomKeyGenerator()); +``` + +## Best Practices + +- **Unique Keys**: Ensure that each idempotency key is unique to each operation. Typically, UUIDs are used for this purpose. +- **Handling Errors**: Handle errors gracefully, especially when an API call with an idempotency key fails. Check the error message to understand whether you should retry the request with the same key or a new key. + +## Conclusionz + +Using idempotency keys in your API requests to Mollie can significantly enhance the reliability of your payment processing system, ensuring that payments are not unintentionally duplicated and that your application behaves predictably even in the face of network and service interruptions. diff --git a/docs/payments.md b/docs/payments.md new file mode 100644 index 000000000..2d98141d4 --- /dev/null +++ b/docs/payments.md @@ -0,0 +1,93 @@ +##### Multicurrency ##### +Since API v2.0 it is now possible to create non-EUR payments for your customers. +A full list of available currencies can be found [in our documentation](https://docs.mollie.com/guides/multicurrency). + +```php +$payment = $mollie->payments->create([ + "amount" => [ + "currency" => "USD", + "value" => "10.00" + ], + //... +]); +``` +_After creation, the `settlementAmount` will contain the EUR amount that will be settled on your account._ + +##### Create fully integrated iDEAL payments ##### +To fully integrate iDEAL payments on your website, follow these additional steps: + +1. Retrieve the list of issuers (banks) that support iDEAL. + +```php +$method = $mollie->methods->get(\Mollie\Api\Types\PaymentMethod::IDEAL, ["include" => "issuers"]); +``` + +Use the `$method->issuers` list to let the customer pick their preferred issuer. + +_`$method->issuers` will be a list of objects. Use the property `$id` of this object in the + API call, and the property `$name` for displaying the issuer to your customer._ + +2. Create a payment with the selected issuer: + +```php +$payment = $mollie->payments->create([ + "amount" => [ + "currency" => "EUR", + "value" => "10.00" + ], + "description" => "My first API payment", + "redirectUrl" => "https://webshop.example.org/order/12345/", + "webhookUrl" => "https://webshop.example.org/mollie-webhook/", + "method" => \Mollie\Api\Types\PaymentMethod::IDEAL, + "issuer" => $selectedIssuerId, // e.g. "ideal_INGBNL2A" +]); +``` + +_The `_links` property of the `$payment` object will contain an object `checkout` with a `href` property, which is a URL that points directly to the online banking environment of the selected issuer. +A short way of retrieving this URL can be achieved by using the `$payment->getCheckoutUrl()`._ + +For a more in-depth example, see [Example - iDEAL payment](https://github.com/mollie/mollie-api-php/blob/master/examples/payments/create-ideal-payment.php). + +#### Retrieving Payments #### +**[Retrieve Payment Documentation](https://docs.mollie.com/reference/v2/payments-api/get-payment)** + +We can use the `$payment->id` to retrieve a payment and check if the payment `isPaid`. + +```php +$payment = $mollie->payments->get($payment->id); + +if ($payment->isPaid()) +{ + echo "Payment received."; +} +``` + +Or retrieve a collection of payments. + +```php +$payments = $mollie->payments->page(); +``` + +For an extensive example of listing payments with the details and status, see [Example - List Payments](https://github.com/mollie/mollie-api-php/blob/master/examples/payments/list-payments.php). + +#### Refunding payments #### +**[Refund Payment Documentation](https://docs.mollie.com/reference/v2/refunds-api/create-payment-refund)** + +Our API provides support for refunding payments. It's important to note that there is no confirmation step, and all refunds are immediate and final. Refunds are available for all payment methods except for paysafecard and gift cards. + +```php +$payment = $mollie->payments->get($payment->id); + +// Refund € 2 of this payment +$refund = $payment->refund([ + "amount" => [ + "currency" => "EUR", + "value" => "2.00" + ] +]); +``` + +#### Payment webhook #### +When the payment status changes, the `webhookUrl` you specified during payment creation will be called. You can use the `id` from the POST parameters to check the status and take appropriate actions. For more details, refer to [Example - Webhook](https://github.com/mollie/mollie-api-php/blob/master/examples/payments/webhook.php). + +For a working example, see [Example - Refund payment](https://github.com/mollie/mollie-api-php/blob/master/examples/payments/refund-payment.php). diff --git a/docs/requests.md b/docs/requests.md new file mode 100644 index 000000000..aa889d6fe --- /dev/null +++ b/docs/requests.md @@ -0,0 +1,48 @@ +# Requests + +## Overview + +The Mollie API client uses request classes to communicate with the Mollie API. Each request class handles specific API endpoints and operations. + +## Sending a Request + +To send a request using the Mollie API client, you typically need to: + +1. **Create an instance of the client**: + ```php + use Mollie\Api\MollieApiClient; + + $mollie = new MollieApiClient(); + $mollie->setApiKey('test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM'); + ``` + +2. **Create and configure the request**: + Depending on the operation, you might need to create an instance of a specific request class and configure it with necessary parameters. + +3. **Send the request**: + Use the client to send the request and handle the response. + + ```php + use Mollie\Api\MollieApiClient; + use Mollie\Api\Http\Data\Money; + use Mollie\Api\Http\Data\CreatePaymentPayload; + use Mollie\Api\Http\Requests\CreatePaymentRequest; + + $mollie = new MollieApiClient(); + $createPaymentRequest = new CreatePaymentRequest( + new CreatePaymentPayload( + 'Test payment', + new Money('EUR', '10.00'), + 'https://example.org/redirect', + 'https://example.org/webhook' + ) + ); + + /** @var \Mollie\Api\Http\Response $response */ + $response = $mollie->send($createPaymentRequest); + + $this->assertEquals(200, $response->status()); + + /** @var \Mollie\Api\Resources\Payment */ + $payment = $response->toResource(); + ``` diff --git a/docs/responses.md b/docs/responses.md new file mode 100644 index 000000000..cd7058112 --- /dev/null +++ b/docs/responses.md @@ -0,0 +1,43 @@ +# Responses + +Whether you interact with the endpoints using the traditional method (`$mollie->payments->...`) or the new `Request` classes, you can always inspect the `Response`. + +## Resource Hydration +By default, the response from the `EndpointCollection`s automatically hydrates into the corresponding `Resource` or `ResourceCollection` objects. You can still access the raw response using the `->getResponse()` method. + +```php +/** @var Mollie\Api\Resources\Payment $payment */ +$payment = $mollie->payments->get('tr_*********'); + +$response = $payment->getResponse(); +``` + +With the Request-based approach, you get a Response by default: + +```php +/** @var Mollie\Api\Http\Response $response */ +$response = $mollie->send(new GetPaymentRequest('tr_*********')); + +/** + * Accessing the response is mainly for debugging, + * like checking the status or inspecting the payload or URL. + */ +$status = $response->status(); +$sentPayload = $response->getPendingRequest()->payload; +$sentUrlWithFilters = $response->getPendingRequest()->getUri(); + +/** @var Mollie\Api\Resources\Payment $payment */ +$payment = $response->toResource(); +``` + +Thanks to the DelegatesToResource Trait in Response, you can still access methods and attributes from the underlying Resource: + +```php +// calling a method on the underlying Mollie\Api\Resources\Payment object +$response->hasSplitPayments(); + +// accessing an attribute on the underlying Mollie\Api\Resources\Payment object +$amount = $response->amount; +``` + +If you prefer the old approach of directly receiving the Resource class, you can enable **auto-hydration** by calling `MollieApiClient::setAutoHydrate()`. diff --git a/docs/testing.md b/docs/testing.md new file mode 100644 index 000000000..f5888d9c7 --- /dev/null +++ b/docs/testing.md @@ -0,0 +1,55 @@ +# Testing with Mollie API Client + +## Overview + +Version 3 of the Mollie API client refines the handling of the test mode parameter: + +- **Automatic Removal of Test Mode**: When using an API key, the test mode parameter is managed based on the key prefix (`test_` or `live_`). +- **Explicit Test Mode Control**: For operations requiring explicit control, such as when using OAuth tokens, you can still pass the `testmode` parameter. + +## Enabling Test Mode + +### Global Test Mode + +You can enable test mode globally on the Mollie client. This setting will apply test mode to all operations performed with the client. + +```php +use Mollie\Api\MollieApiClient; + +$mollie = new MollieApiClient(); +$mollie->setApiKey("test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM"); +$mollie->test(true); // Enable test mode globally +``` + +### Per Request Test Mode + +For specific control, you can enable test mode per request. This is useful for mixed-mode operations. + +```php +// Creating a payment in test mode +use Mollie\Api\MollieApiClient; +use Mollie\Api\Http\Data\Money; +use Mollie\Api\Http\Data\CreatePaymentPayload; +use Mollie\Api\Http\Requests\CreatePaymentRequest; + +$mollie = new MollieApiClient(); +$createPaymentRequest = new CreatePaymentRequest( + new CreatePaymentPayload( + 'Test payment', + new Money('EUR', '10.00'), + 'https://example.org/redirect', + 'https://example.org/webhook' + ) +); + +$mollie->send($createPaymentRequest->test(true)); +``` + +### Using Test Mode with Endpoint Collections + +When using endpoint collections, pass the test mode parameter directly to methods that support it. + +```php +// Fetch a customer in test mode +$customer = $mollie->customers->get('cust_12345678', testmode: true); +``` diff --git a/examples/captures/create-capture.php b/examples/captures/create-capture.php index a51030ea8..65d374406 100644 --- a/examples/captures/create-capture.php +++ b/examples/captures/create-capture.php @@ -1,15 +1,20 @@ paymentCaptures->createForId('tr_WDqYK6vllg', [ - "amount" => [ - "currency" => "EUR", - "value" => "5.00", - ], - "description" => "Order #12345", - ]); + $response = $mollie->send(new CreatePaymentCaptureRequest('tr_WDqYK6vllg', new CreatePaymentCapturePayload( + 'Order #12345', + new Money('EUR', '5.00') + ))); + + $capture = $response->toResource(); - echo "
New capture created " . htmlspecialchars($capture->id) . " (" . htmlspecialchars($capture->description) . ").
"; + echo 'New capture created '.htmlspecialchars($capture->id).' ('.htmlspecialchars($capture->description).').
'; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/captures/get-capture.php b/examples/captures/get-capture.php index 77b658d7c..0f6e076dd 100644 --- a/examples/captures/get-capture.php +++ b/examples/captures/get-capture.php @@ -1,13 +1,16 @@ payments->get('tr_WDqYK6vllg'); - $capture = $payment->getCapture('cpt_4qqhO89gsT'); + $response = $mollie->send(new GetPaymentCaptureRequest('tr_WDqYK6vllg', 'cpt_4qqhO89gsT')); - $amount = $capture->amount->currency . ' ' . $capture->amount->value; + $capture = $response->toResource(); + $amount = $capture->amount->currency.' '.$capture->amount->value; - echo 'Captured ' . $amount; + echo 'Captured '.$amount; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/captures/list-captures.php b/examples/captures/list-captures.php index 8567db76d..2ead8b80f 100644 --- a/examples/captures/list-captures.php +++ b/examples/captures/list-captures.php @@ -1,13 +1,16 @@ payments->get('tr_WDqYK6vllg'); - $captures = $payment->captures(); + $response = $mollie->send(new GetPaginatedPaymentCapturesRequest('tr_WDqYK6vllg')); - foreach ($captures as $capture) { - $amount = $capture->amount->currency . ' ' . $capture->amount->value; - echo 'Captured ' . $amount . ' for payment ' . $payment->id; + foreach ($payment = $response->toResource() as $capture) { + $amount = $capture->amount->currency.' '.$capture->amount->value; + echo 'Captured '.$amount.' for payment '.$payment->id; } } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/client-links/create-client-link.php b/examples/client-links/create-client-link.php index 789a90fe5..941a1babb 100644 --- a/examples/client-links/create-client-link.php +++ b/examples/client-links/create-client-link.php @@ -1,18 +1,24 @@ clientLinks->create([ - "owner" => [ - "email" => "foo@test.com", - "givenName" => "foo", - "familyName" => "bar", - "locale" => "nl_NL", - ], - "name" => "Foo Company", - "address" => [ - "streetAndNumber" => "Keizersgracht 313", - "postalCode" => "1016 EE", - "city" => "Amsterdam", - "country" => "nl", - ], - "registrationNumber" => "30204462", - "vatNumber" => "NL123456789B01", - ]); + $response = $mollie->send(new CreateClientLinkRequest(new CreateClientLinkPayload( + new Owner('foo@test.com', 'foo', 'bar', 'nl_NL'), + 'Foo Company', + new OwnerAddress('NL', 'Keizersgracht 313', '1016 EE', 'Amsterdam'), + '30204462', + 'NL123456789B01', + ))); + + $clientLink = $response->toResource(); /** * Get the redirect url for the client link, by passing in the 'client_id' of the your app, @@ -46,7 +44,7 @@ * * For more info see: https://docs.mollie.com/reference/oauth2/authorize#parameters */ - $redirectUrl = $clientLink->getRedirectUrl("app_j9Pakf56Ajta6Y65AkdTtAv", "decafbad", "force", [ + $redirectUrl = $clientLink->getRedirectUrl('app_j9Pakf56Ajta6Y65AkdTtAv', 'decafbad', 'force', [ 'onboarding.read', 'onboarding.write', ]); @@ -55,7 +53,7 @@ * Send the customer off to finalize the organization creation. * This request should always be a GET, thus we enforce 303 http response code */ - header("Location: " . $redirectUrl, true, 303); + header('Location: '.$redirectUrl, true, 303); } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/customers/create-customer-first-payment.php b/examples/customers/create-customer-first-payment.php index 0775f27b4..96761e314 100644 --- a/examples/customers/create-customer-first-payment.php +++ b/examples/customers/create-customer-first-payment.php @@ -1,19 +1,27 @@ customers->page(null, 1)[0]; + $customer = $mollie->send(new GetPaginatedCustomerRequest)->toResource()[0]; /* * Generate a unique order id for this example. It is important to include this unique attribute @@ -24,7 +32,7 @@ /* * Determine the url parts to these example files. */ - $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http"; + $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? 'https' : 'http'; $hostname = $_SERVER['HTTP_HOST']; /** @@ -32,21 +40,20 @@ * * @See: https://docs.mollie.com/reference/v2/customers-api/create-customer-payment */ - $payment = $customer->createPayment([ - "amount" => [ - "value" => "10.00", // You must send the correct number of decimals, thus we enforce the use of strings - "currency" => "EUR", - ], - "description" => "First payment - Order #{$orderId}", - "redirectUrl" => "{$protocol}://{$hostname}/payments/return.php?order_id={$orderId}", - "webhookUrl" => "{$protocol}://{$hostname}/payments/webhook.php", - "metadata" => [ - "order_id" => $orderId, - ], + $payload = CreatePaymentPayloadFactory::new([ + 'description' => "First payment - Order #{$orderId}", + 'amount' => new Money('EUR', '10.00'), + 'redirectUrl' => "{$protocol}://{$hostname}/payments/return.php?order_id={$orderId}", + 'webhookUrl' => "{$protocol}://{$hostname}/payments/webhook.php", + 'metadata' => new Metadata([ + 'order_id' => $orderId, + ]), + 'sequenceType' => SequenceType::FIRST, + ])->create(); - // Flag this payment as a first payment to allow recurring payments later. - "sequenceType" => \Mollie\Api\Types\SequenceType::SEQUENCETYPE_FIRST, - ]); + $payment = $mollie->send( + new CreateCustomerPaymentRequest($customer->id, $payload) + ); /* * In this example we store the order with its payment status in a database. @@ -60,7 +67,7 @@ * After completion, the customer will have a pending or valid mandate that can be * used for recurring payments and subscriptions. */ - header("Location: " . $payment->getCheckoutUrl(), true, 303); + header('Location: '.$payment->getCheckoutUrl(), true, 303); } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/customers/create-customer-payment.php b/examples/customers/create-customer-payment.php index 5713dd18d..a8b278dc9 100644 --- a/examples/customers/create-customer-payment.php +++ b/examples/customers/create-customer-payment.php @@ -1,4 +1,5 @@ createPayment([ - "amount" => [ - "value" => "10.00", // You must send the correct number of decimals, thus we enforce the use of strings - "currency" => "EUR", + 'amount' => [ + 'value' => '10.00', // You must send the correct number of decimals, thus we enforce the use of strings + 'currency' => 'EUR', ], - "description" => "Order #{$orderId}", - "redirectUrl" => "{$protocol}://{$hostname}/payments/return.php?order_id={$orderId}", - "webhookUrl" => "{$protocol}://{$hostname}/payments/webhook.php", - "metadata" => [ - "order_id" => $orderId, + 'description' => "Order #{$orderId}", + 'redirectUrl' => "{$protocol}://{$hostname}/payments/return.php?order_id={$orderId}", + 'webhookUrl' => "{$protocol}://{$hostname}/payments/webhook.php", + 'metadata' => [ + 'order_id' => $orderId, ], ]); @@ -54,7 +55,7 @@ * Send the customer off to complete the payment. * This request should always be a GET, thus we enforce 303 http response code */ - header("Location: " . $payment->getCheckoutUrl(), true, 303); + header('Location: '.$payment->getCheckoutUrl(), true, 303); } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/customers/create-customer-recurring-payment.php b/examples/customers/create-customer-recurring-payment.php index dedae9179..039ee5b8c 100644 --- a/examples/customers/create-customer-recurring-payment.php +++ b/examples/customers/create-customer-recurring-payment.php @@ -1,4 +1,5 @@ customers->page(null, 1)[0]; - + $customer = $mollie->customers->collect(null, 1)[0]; + /* * Generate a unique order id for this example. */ @@ -23,7 +24,7 @@ /* * Determine the url parts to these example files. */ - $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http"; + $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? 'https' : 'http'; $hostname = $_SERVER['HTTP_HOST']; /** @@ -32,20 +33,20 @@ * @See: https://docs.mollie.com/reference/v2/customers-api/create-customer-payment */ $payment = $customer->createPayment([ - "amount" => [ - "value" => "10.00", // You must send the correct number of decimals, thus we enforce the use of strings - "currency" => "EUR", + 'amount' => [ + 'value' => '10.00', // You must send the correct number of decimals, thus we enforce the use of strings + 'currency' => 'EUR', ], - "description" => "On-demand payment - Order #{$orderId}", - "webhookUrl" => "{$protocol}://{$hostname}/payments/webhook.php", - "metadata" => [ - "order_id" => $orderId, + 'description' => "On-demand payment - Order #{$orderId}", + 'webhookUrl' => "{$protocol}://{$hostname}/payments/webhook.php", + 'metadata' => [ + 'order_id' => $orderId, ], // Flag this payment as a recurring payment. - "sequenceType" => \Mollie\Api\Types\SequenceType::SEQUENCETYPE_RECURRING, + 'sequenceType' => \Mollie\Api\Types\SequenceType::RECURRING, ]); - + /* * In this example we store the order with its payment status in a database. */ @@ -55,8 +56,8 @@ * The payment will be either pending or paid immediately. The customer * does not have to perform any payment steps. */ - echo "Selected mandate is '" . htmlspecialchars($payment->mandateId) . "' (" . htmlspecialchars($payment->method) . ").
\n"; - echo "The payment status is '" . htmlspecialchars($payment->status) . "'.
\n"; + echo "Selected mandate is '".htmlspecialchars($payment->mandateId)."' (".htmlspecialchars($payment->method).").
\n"; + echo "The payment status is '".htmlspecialchars($payment->status)."'.
\n"; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/customers/create-customer.php b/examples/customers/create-customer.php index 3608ab9cb..eab9c2a6a 100644 --- a/examples/customers/create-customer.php +++ b/examples/customers/create-customer.php @@ -1,4 +1,5 @@ customers->create([ - "name" => "Luke Skywalker", - "email" => "luke@example.org", - "metadata" => [ - "isJedi" => true, + 'name' => 'Luke Skywalker', + 'email' => 'luke@example.org', + 'metadata' => [ + 'isJedi' => true, ], ]); - echo "New customer created " . htmlspecialchars($customer->id) . " (" . htmlspecialchars($customer->name) . ").
"; + echo 'New customer created '.htmlspecialchars($customer->id).' ('.htmlspecialchars($customer->name).').
'; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/customers/delete-customer.php b/examples/customers/delete-customer.php index 188e92640..2db397211 100644 --- a/examples/customers/delete-customer.php +++ b/examples/customers/delete-customer.php @@ -1,4 +1,5 @@ customers->delete("cst_fE3F6nvX"); - echo "Customer deleted!
"; + $mollie->customers->delete('cst_fE3F6nvX'); + echo 'Customer deleted!
'; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/customers/list-customer-payments.php b/examples/customers/list-customer-payments.php index ae7329baa..39d0167dd 100644 --- a/examples/customers/list-customer-payments.php +++ b/examples/customers/list-customer-payments.php @@ -1,4 +1,5 @@ customers->page(null, 1)[0]; + $customer = $mollie->customers->collect(null, 1)[0]; /* * Get the all payments for this API key ordered by newest. */ $payments = $customer->payments(); - echo "Customer updated: " . htmlspecialchars($customer->name) . "
"; + echo 'Customer updated: '.htmlspecialchars($customer->name).'
'; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/functions.php b/examples/functions.php index d97ef07e7..4c9c29981 100644 --- a/examples/functions.php +++ b/examples/functions.php @@ -1,4 +1,5 @@ setApiKey("test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM"); +$mollie = new \Mollie\Api\MollieApiClient; +$mollie->setApiKey('test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM'); diff --git a/examples/initialize_with_oauth.php b/examples/initialize_with_oauth.php index a12ef401a..669175c46 100644 --- a/examples/initialize_with_oauth.php +++ b/examples/initialize_with_oauth.php @@ -7,13 +7,13 @@ ini_set('display_startup_errors', '1'); error_reporting(E_ALL); -require_once __DIR__ . "/../vendor/autoload.php"; -require_once __DIR__ . "/functions.php"; +require_once __DIR__.'/../vendor/autoload.php'; +require_once __DIR__.'/functions.php'; /* * Initialize the Mollie API library with OAuth. * * See: https://docs.mollie.com/oauth/overview */ -$mollie = new \Mollie\Api\MollieApiClient(); -$mollie->setAccessToken("access_Wwvu7egPcJLLJ9Kb7J632x8wJ2zMeJ"); +$mollie = new \Mollie\Api\MollieApiClient; +$mollie->setAccessToken('access_Wwvu7egPcJLLJ9Kb7J632x8wJ2zMeJ'); diff --git a/examples/invoices/list-invoices.php b/examples/invoices/list-invoices.php index 53b539ebb..be0c45158 100644 --- a/examples/invoices/list-invoices.php +++ b/examples/invoices/list-invoices.php @@ -1,4 +1,5 @@ invoices->all(); foreach ($invoices as $invoice) { - echo 'Period | Description | Count | VAT Percentage | Amount | |||||
---|---|---|---|---|---|---|---|---|---|
' . htmlspecialchars($line->period) . ' | '; - echo '' . htmlspecialchars($line->description) . ' | '; - echo '' . htmlspecialchars($line->count) . ' | '; - echo '' . htmlspecialchars($line->vatPercentage) . ' | '; - echo '' . htmlspecialchars($line->amount->currency . " " . $line->amount->value) . ' | '; + echo ''.htmlspecialchars($line->period).' | '; + echo ''.htmlspecialchars($line->description).' | '; + echo ''.htmlspecialchars($line->count).' | '; + echo ''.htmlspecialchars($line->vatPercentage).' | '; + echo ''.htmlspecialchars($line->amount->currency.' '.$line->amount->value).' | '; echo '
Gross Total | ' . htmlspecialchars($invoice->grossAmount->value . " " . $invoice->grossAmount->currency) . ' | ||||||||
Gross Total | '.htmlspecialchars($invoice->grossAmount->value.' '.$invoice->grossAmount->currency).' |
Mandate created with id " . $mandate->id . " for customer " . $customer->name . "
"; + echo 'Mandate created with id '.$mandate->id.' for customer '.$customer->name.'
'; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/mandates/list-mandates.php b/examples/mandates/list-mandates.php index 7d0161643..fd37db867 100644 --- a/examples/mandates/list-mandates.php +++ b/examples/mandates/list-mandates.php @@ -1,4 +1,5 @@ customers->get("cst_cUa8HjKBus"); + $customer = $mollie->customers->get('cst_cUa8HjKBus'); /* * List the mandates of this customer */ - echo "Mandate has been successfully revoked.
"; + echo 'Mandate has been successfully revoked.
'; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/orders/cancel-order-lines.php b/examples/orders/cancel-order-lines.php deleted file mode 100644 index f0f827f7c..000000000 --- a/examples/orders/cancel-order-lines.php +++ /dev/null @@ -1,44 +0,0 @@ -orders->get($orderId); - $line = $order->lines()->get($lineId); - if ($line && $line->isCancelable) { - $order->cancelLines([ - 'lines' => [ - [ - 'id' => $lineId, - 'quantity' => 1, // optional parameter - ], - ], - ]); - - $updatedOrder = $mollie->orders->get($orderId); - - echo 'Your order ' . $order->id . ' was updated:'; - foreach ($order->lines as $line) { - echo $line->description . '. Status: ' . $line->status . '.'; - } - } else { - echo "Unable to cancel line " . $lineId . " for your order " . $orderId . "."; - } -} catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); -} diff --git a/examples/orders/cancel-order.php b/examples/orders/cancel-order.php deleted file mode 100644 index 4c4143594..000000000 --- a/examples/orders/cancel-order.php +++ /dev/null @@ -1,26 +0,0 @@ -orders->get("ord_pbjz8x"); - if ($order->isCancelable) { - $canceledOrder = $order->cancel(); - echo "Your order " . $order->id . " has been canceled."; - } else { - echo "Unable to cancel your order " . $order->id . "."; - } -} catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); -} diff --git a/examples/orders/create-order.php b/examples/orders/create-order.php deleted file mode 100644 index 9dc431899..000000000 --- a/examples/orders/create-order.php +++ /dev/null @@ -1,118 +0,0 @@ -orders->create([ - "amount" => [ - "value" => "1027.99", - "currency" => "EUR", - ], - "billingAddress" => [ - "streetAndNumber" => "Keizersgracht 313", - "postalCode" => "1016 EE", - "city" => "Amsterdam", - "country" => "nl", - "givenName" => "Luke", - "familyName" => "Skywalker", - "email" => "luke@skywalker.com", - ], - "shippingAddress" => [ - "streetAndNumber" => "Keizersgracht 313", - "postalCode" => "1016 EE", - "city" => "Amsterdam", - "country" => "nl", - "givenName" => "Luke", - "familyName" => "Skywalker", - "email" => "luke@skywalker.com", - ], - "metadata" => [ - "order_id" => $orderId, - ], - "consumerDateOfBirth" => "1958-01-31", - "locale" => "en_US", - "orderNumber" => strval($orderId), - "redirectUrl" => "{$protocol}://{$hostname}{$path}/return.php?order_id={$orderId}", - "webhookUrl" => "{$protocol}://{$hostname}{$path}/webhook.php", - "method" => "ideal", - "lines" => [ - [ - "sku" => "5702016116977", - "name" => "LEGO 42083 Bugatti Chiron", - "productUrl" => "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", - "imageUrl" => 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$', - "quantity" => 2, - "vatRate" => "21.00", - "unitPrice" => [ - "currency" => "EUR", - "value" => "399.00", - ], - "totalAmount" => [ - "currency" => "EUR", - "value" => "698.00", - ], - "discountAmount" => [ - "currency" => "EUR", - "value" => "100.00", - ], - "vatAmount" => [ - "currency" => "EUR", - "value" => "121.14", - ], - ], - [ - "type" => "digital", - "sku" => "5702015594028", - "name" => "LEGO 42056 Porsche 911 GT3 RS", - "productUrl" => "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056", - "imageUrl" => 'https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$', - "quantity" => 1, - "vatRate" => "21.00", - "unitPrice" => [ - "currency" => "EUR", - "value" => "329.99", - ], - "totalAmount" => [ - "currency" => "EUR", - "value" => "329.99", - ], - "vatAmount" => [ - "currency" => "EUR", - "value" => "57.27", - ], - ], - ], - ]); - - /* - * Send the customer off to complete the order payment. - * This request should always be a GET, thus we enforce 303 http response code - */ - header("Location: " . $order->getCheckoutUrl(), true, 303); -} catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); -} diff --git a/examples/orders/list-methods.php b/examples/orders/list-methods.php deleted file mode 100644 index 5289b160c..000000000 --- a/examples/orders/list-methods.php +++ /dev/null @@ -1,28 +0,0 @@ -methods->all(['resource' => 'orders']); - foreach ($methods as $method) { - echo 'Billed to | Shipped to | Total amount |
---|---|---|
' . htmlspecialchars($order->shippingAddress->givenName) . ' ' . htmlspecialchars($order->shippingAddress->familyName) . ' | '; - echo '' . htmlspecialchars($order->billingAddress->givenName) . ' ' . htmlspecialchars($order->billingAddress->familyName) . ' | '; - echo '' . htmlspecialchars($order->amount->currency) . str_replace('.', ',', htmlspecialchars($order->amount->value)) . ' | '; - echo '