1. Go to this page and download the library: Download romansh/omnipay-creem library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
romansh / omnipay-creem example snippets
use Omnipay\Omnipay;
$gateway = Omnipay::create('Creem');
$gateway->setApiKey('your_api_key');
$gateway->setTestMode(true);
$response = $gateway->purchase([
'productId' => 'prod_xxxxxxxxx', // Creem product ID
'transactionId' => 'ORDER-12345', // your unique order/request ID
'returnUrl' => 'https://your-site.com/return',
'card' => [
'email' => '[email protected]',
'name' => 'John Doe',
],
'description' => 'Premium plan',
])->send();
if ($response->isRedirect()) {
$response->redirect(); // send the customer to Creem checkout
// — or get the URL to use in your own redirect / JS —
// $checkoutUrl = $response->getRedirectUrl();
// $checkoutId = $response->getTransactionReference();
} else {
echo 'Error: ' . $response->getMessage();
}
$gateway->setWebhookSecret('your_webhook_secret');
$response = $gateway->completePurchase()->send();
switch ($response->getEventType()) {
case 'checkout.completed':
$orderId = $response->getTransactionId(); // your request_id
$customer = $response->getCustomer(); // ['id' => …, 'email' => …]
$product = $response->getProduct(); // ['id' => …, 'name' => …]
// mark order as paid …
break;
case 'subscription.active':
case 'subscription.renewed':
// grant / extend access
break;
case 'subscription.trialing':
// grant trial access
break;
case 'subscription.canceled':
case 'subscription.expired':
// revoke access
break;
case 'refund.created':
// process refund
break;
}
http_response_code(200);
echo json_encode(['status' => 'ok']);