5.0 KiB
5.0 KiB
Create a Client Link
How to create a client link to onboard new merchants to Mollie through your app.
The Code
use Mollie\Api\Http\Data\Owner;
use Mollie\Api\Resources\ClientLink;
use Mollie\Api\Http\Data\OwnerAddress;
use Mollie\Api\Http\Requests\CreateClientLinkRequest;
use Mollie\Api\Types\ApprovalPrompt;
try {
// Create a client link for a new merchant
/** @var ClientLink $clientLink */
$clientLink = $mollie->send(
new CreateClientLinkRequest(
owner: new Owner(
email: 'merchant@example.com',
givenName: 'John',
familyName: 'Doe',
locale: 'en_US'
),
name: 'Example Store',
address: new OwnerAddress(
country: 'NL',
streetAndNumber: 'Keizersgracht 313',
postalCode: '1016 EE',
city: 'Amsterdam'
),
registrationNumber: '30204462',
vatNumber: 'NL123456789B01'
)
);
// Generate the redirect URL for the merchant
$redirectUrl = $clientLink->getRedirectUrl(
client_id: 'app_j9Pakf56Ajta6Y65AkdTtAv',
state: bin2hex(random_bytes(8)), // Random state to prevent CSRF
scopes: [
'onboarding.read',
'onboarding.write'
],
approval_prompt: ApprovalPrompt::Force->value // Always show login screen
);
// Redirect the merchant to complete their onboarding
header('Location: ' . $redirectUrl, true, 303);
} catch (\Mollie\Api\Exceptions\ApiException $e) {
echo "API call failed: " . htmlspecialchars($e->getMessage());
}
The Response
$clientLink->id; // "csr_wJPGBj7sFr"
$clientLink->resource; // "client-link"
$clientLink->_links; // \stdClass with the clientLink href
ClientLink declares only id and _links (plus resource from the base
resource). There is no status, createdAt or expiresAt on this resource;
build the onboarding URL with getRedirectUrl() and track onboarding state
through the Onboarding API.
Additional Notes
- Client links are used to onboard new merchants to Mollie through your app
- The link expires after 24 hours, though the resource does not expose an expiry field
getRedirectUrl()takesclient_id,state,scopesandapproval_prompt;approval_promptaccepts onlyautoorforceand throws otherwise- Required merchant information:
- Owner details (name, email, locale)
- Organization details (name, address)
- Registration number (Chamber of Commerce number)
- VAT number (if applicable)
- The
stateparameter should be:- Random and unique
- Stored in your session
- Verified when the merchant returns to prevent CSRF attacks
- Available scopes (see Permissions):
balances.read: View the merchant's balances informationbalance-transfers.read: View the merchant's balance transfersbalance-transfers.write: Create balance transfers for the merchantcustomers.read: View the merchant's customerscustomers.write: Manage the merchant's customersexternal-accounts.read: View the merchant's external accountsexternal-accounts.write: Manage the merchant's external accountsinvoices.read: View the merchant's invoicesmandates.read: View the merchant's mandatesmandates.write: Manage the merchant's mandatesonboarding.read: View the merchant's onboarding statusonboarding.write: Submit onboarding data for the merchantorders.read: View the merchant's ordersorders.write: Manage the merchant's ordersorganizations.read: View the merchant's organizational detailsorganizations.write: Change the merchant's organizational detailspayment-links.read: View the merchant's payment linkspayment-links.write: Create payment links for the merchantpayments.read: View the merchant's payments, chargebacks and payment methodspayments.write: Create payments for the merchant (added to the merchant's balance)persons.read: View the merchant's persons and stakeholderspersons.write: Manage the merchant's persons and stakeholdersprofiles.read: View the merchant's website profilesprofiles.write: Manage the merchant's website profilesrefunds.read: View the merchant's refundsrefunds.write: Create or cancel refundssettlements.read: View the merchant's settlementsshipments.read: View the merchant's order shipmentsshipments.write: Manage the merchant's order shipmentssubscriptions.read: View the merchant's subscriptionssubscriptions.write: Manage the merchant's subscriptionsterminals.read: View the merchant's point-of-sale terminalsterminals.write: Manage the merchant's point-of-sale terminals
- The merchant will need to:
- Create a Mollie account or log in
- Connect their account to your app
- Complete the onboarding process
- You can track the onboarding status through the OAuth APIs