payfurl / phpsdk
The payFURL API for PHP: charges, customers, payment methods, subscriptions and the rest of the public REST API
Requires
- php: ^8.2
- ext-curl: *
- ext-json: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.64
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-master
- v3.0.0
- v2.3.0
- v2.2.3
- v2.2.2
- v2.2.1
- v2.2.0
- v2.1.6
- v2.1.5
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.0
- v1.9.8
- v1.9.7
- v1.9.6
- v1.9.5
- v1.9.4
- v1.9.3
- v1.9.2
- v1.9.1
- v1.9
- 1.8
- v1.7
- v1.6
- v1.5
- v1.4
- v1.3
- v1.2
- v1.1
- dev-PAY-4235/optional-group-reference-string-payment-link-types
- dev-PAY-4235/readme-for-sdk-users-not-maintainers
- dev-PAY-4235/releases-rely-on-packagists-github-hook
- dev-PAY-4235/php-sdk-v3-types-unit-tests-current-api-e2e-in-the-platform-release-ci
- dev-PAY-4235/release-2-3-0
- dev-PAY-4450/update-sdk
- dev-PAY-4285/add-support-for-metadata-with-payment-links
- dev-PAY-4272/serversdk-payment-link-helpers
- dev-PAY-4249/add-metadata-parameters-to-server-sdks-when-creating-batch
- dev-PAY-4238/add-automated-test-for-payment-links-into-serve-sdks
- dev-PAY-4198/add-pay-by-link-support-into-server-sdks
- dev-PAY-4219/implement-recurring-flags-with-ipg-support-first
- dev-remove-cache
- dev-PAY-3996/remove-us-region-in-sandbox-and-jp-region-in-development
- dev-PAY-3675/create-centralised-subscription-option-for-webhooks
- dev-PAY-3638-add-support-in-java-net-php-sdks
- dev-PAY-3640/add-ability-to-pause-a-subscription
- dev-PAY-3449/review-missing-parameters-in-java-php-net-sdk
- dev-PAY-3412/phone-number-and-email-are-not-collected-when-making-a-magento-payment
- dev-alex-payfurl-patch-1
- dev-PAY-3402/add-metadata-parameter-into-sdks-when-creating-a-subscription
- dev-array_intersect_key_fix
- dev-PAY-3304/add-server-sdk-support-in-for-new-search-parameters
- dev-PAY-3323-fix-click-to-pay-filtering-in-web-interface
- dev-PAY-3262-add-support-for-updating-payment-method-into-sdks
- dev-feature/add-webhook-for-batch
- dev-PAY-3041/sdk-for-subscription
- dev-PAY-3104/add-new-parameters-to-sdks
- dev-PAY-2971/php-sdk-doesnt-perform-unit-testing-on-github
- dev-feature/PAY-2933-make-input-parameters-camel-case-compatible
- dev-PAY-2869-add-support-for-directdebit-with-ezidebit
- dev-PAY-2909/add-missing-endpoint-post-payment-methodprovider-token
- dev-PAY-2892/add-batchtransaction-support-into-sdks
- dev-PAY-2838/magento-plugin-doesnt-collect-customer-information
- dev-PAY-2486/we-want-to-add-support-for-a-3ds-check-after-the-authorisation-is
- dev-PAY-2362/split-payment-options-rather-than-displaying-a-single-payfurl-payment
- dev-PAY-2483/create-api-method-to-delete-a-provider-in-the-api-not-just-apiweb
- dev-PAY-2402/magnento-plugin-doesnt-work-in-production
- dev-PAY-2390/java-sdk-is-missing-metadata-parameter-for-post-customerprovider-token
- dev-PAY-2262/add-support-on-java-php-and-c-sdks
- dev-feature/add-descriptor
- dev-PAY-2276/test-using-our-magento-plugin-with-httpswwwbecextechcomau
- dev-feature/add-new-region
- dev-feature/support-multi-region
- dev-PAY-1543/remove-ability-to-call-payment-methodcheckout-using-secret-key
- dev-PAY-1523/add-auto-tests-for-php-sdk
- dev-PAY-1434_Add-Metadata-into-charges
- dev-PAY-1410/php-sdk
- dev-PAY-1346-implement-managing-default-payment-method-for-a-customer
- dev-PAY-1258/add-support-for-updateprovider
- dev-PAY-1247/level-2level-3-data-fix
- dev-PAY-1225-verify-payment-token-for-post-customerpayment-token
- dev-PAY-1170-add-error-code-support-into-php-sdk
- dev-PAY-1151
- dev-vault+3ds
- dev-PAY-407-add-in-support-for-new-methods-in-sdks
- dev-PAY-166---least-cost-routing
This package is auto-updated.
Last update: 2026-11-10 02:37:12 UTC
README
The payFURL API for PHP: take payments on 60+ gateways through one integration. The SDK covers the public REST API with the account's secret key: charges, customers, payment methods, subscriptions, batches, payment links, transfers, vaults, providers, webhook subscriptions, settlements and disputes. API reference: docs.payfurl.com.
3.0 is a breaking release. It is typed, needs PHP 8.2, and replaces 2.x's static classes with a client. UPGRADE.md maps every 2.x method to its replacement. 2.x stays installable with
^2.2.
Install
composer require payfurl/phpsdk:^3.0
It needs PHP 8.2 or later with the curl and json extensions, and nothing else: no other Composer package, so
it can be bundled in a plugin without clashing with another plugin's copy of one.
Supported PHP versions
Every PHP version still supported upstream: 8.2, 8.3, 8.4 and 8.5 today, each one tested in CI. Support for a PHP version ends in the first minor release after its end of life, and the changelog says so.
Quick start
use payFURL\Sdk\Environment; use payFURL\Sdk\Model\NewChargeToken; use payFURL\Sdk\PayfurlClient; $payfurl = new PayfurlClient(getenv('PAYFURL_SECRET_KEY'), Environment::Sandbox); // $token comes from the browser SDK (@payfurl/client), which collects the card on your checkout page. $charge = $payfurl->charges->createWithToken(new NewChargeToken( amount: 20.0, token: $token, currency: 'AUD', reference: 'order-1001', )); echo $charge->chargeId, ' ', $charge->status?->value; // 3f83ab8f... SUCCESS
Requests are models with named arguments: a required field is a required argument. They are named as in the API
(NewChargeToken is the API's NewChargeToken) and live in payFURL\Sdk\Model. Responses are models with
typed properties, every one nullable; toArray() returns the response as the API sent it.
Environments and regions
Environment |
Host |
|---|---|
Production |
https://api.payfurl.com, or the region's own (https://api-au.payfurl.com) |
Sandbox |
https://sandbox-api.payfurl.com, or https://sandbox-api-au.payfurl.com |
Development |
payFURL's own development environment |
Local |
https://localhost:5001, an API running on this machine, with TLS verification off |
The region comes from the key: its last part (sectest...-au) is the account's region. ClientOptions changes
the rest:
use payFURL\Sdk\ClientOptions; $payfurl = new PayfurlClient($secretKey, 'production', new ClientOptions( baseUrl: null, // another host, such as a proxy timeoutMilliseconds: 30000, // per request; 60 seconds by default maxRetries: 2, // GETs only, see below ));
One client per key: a store with several payFURL accounts makes one client per account.
Examples
use payFURL\Sdk\Model\{CardRequestInformation, ChargeSearch, DisputeSearch, NewChargePaymentMethod, NewCustomerToken, NewPaymentMethodCard, NewWebhookSubscription, SubscriptionCreate, SubscriptionInterval, SubscriptionStatus, TransactionStatus, WebhookType}; // Charges: refund part of one, capture an authorised one, search $payfurl->charges->refund($chargeId, amount: 5.0, comment: 'damaged'); $payfurl->charges->capture($authorisedChargeId); $list = $payfurl->charges->search(new ChargeSearch(status: TransactionStatus::Success, limit: 50)); // Customers and saved payment methods $customer = $payfurl->customers->createWithToken(new NewCustomerToken(token: $token, email: 'jo@example.com')); $paymentMethods = $payfurl->customers->paymentMethods($customer->customerId); $payfurl->charges->createWithPaymentMethod(new NewChargePaymentMethod(amount: 15.0, paymentMethodId: $paymentMethods[0]->paymentMethodId)); // A card saved without a customer, on a named gateway $payfurl->paymentMethods->createWithCard(new NewPaymentMethodCard( providerId: $providerId, paymentInformation: new CardRequestInformation(cardNumber: '4111111111111111', expiryDate: '12/30', ccv: '123'), )); // Subscriptions: monthly, then paused $subscription = $payfurl->subscriptions->create(new SubscriptionCreate( amount: 9.95, paymentMethodId: $paymentMethodId, currency: 'AUD', interval: SubscriptionInterval::Month, frequency: 1, )); $payfurl->subscriptions->updateStatus($subscription->subscriptionId, SubscriptionStatus::Suspended); // Webhooks: where they go $payfurl->webhookSubscriptions->create(new NewWebhookSubscription(url: 'https://shop.example/payfurl', types: [WebhookType::Transaction])); // Disputes, settlements, what the checkout can show $disputes = $payfurl->disputes->search(new DisputeSearch(dueBefore: new DateTimeImmutable('+7 days'))); $settlements = $payfurl->settlements->search(new DateTimeImmutable('first day of last month')); $providers = $payfurl->info->providers(amount: 20.0, currency: 'AUD', browserSdkVersion: '4.11.0');
| Property | Methods |
|---|---|
charges |
createWithCard, createWithCardLeastCost, createWithCustomer, createWithPaymentMethod, createWithToken, createWithBankAccount, createWithNetworkToken, get, search, refund, capture, void |
customers |
createWithCard, createWithToken, createWithPayTo, createWithProviderToken, createWithSingleUseToken, createWithBankAccount, get, search, update, delete, paymentMethods, addPaymentMethodWithCard, addPaymentMethodWithToken, addPaymentMethodWithPayTo, addPaymentMethodWithBankAccount |
paymentMethods |
createWithCard, createWithVault, createWithPayTo, createWithToken, createWithSingleUseToken, createWithProviderToken, createWithBankAccount, get, search, update, delete |
subscriptions |
create, get, search, update, updateStatus, delete |
batches |
createWithPaymentMethods, get, status, search |
paymentLinks |
create, get, search, and the static imageDataUri |
transfers |
create, get, search |
vaults |
create, get, delete |
providers |
create, update, delete |
tokens |
get, search |
webhookSubscriptions |
create, get, search, delete |
settlements |
search |
disputes |
get, search |
info |
providers (takes the public key too) |
| the client itself | root(), version() |
Tokens are made in the browser with the public key, by the browser SDK; the server SDK charges them.
Errors and retries
Every error is a payFURL\Sdk\Exception\PayfurlException:
| Exception | When |
|---|---|
AuthenticationException |
the key is wrong or may not call the endpoint (HTTP 401, 403) |
InvalidRequestException |
the API rejected the fields (HTTP 400, ErrorCode::ValidationError; $details names them), or an id was empty |
NotFoundException |
no such resource (HTTP 404) |
ApiException |
any other API error: a declined charge (HTTP 400 with its code), a server error (5xx) |
NetworkException |
no response: a network error, or a timeout ($timedOut) |
use payFURL\Sdk\ErrorCode; use payFURL\Sdk\Exception\ApiException; use payFURL\Sdk\Exception\NetworkException; try { $charge = $payfurl->charges->createWithToken($request); } catch (ApiException $e) { // $e->httpCode, $e->errorCode (ErrorCode::tryFrom($e->errorCode)), $e->isRetryable, $e->details, // $e->gatewayCode, $e->gatewayMessage, $e->chargeId (the declined charge), $e->traceId (for support) } catch (NetworkException $e) { // The charge may still have gone through: search by its reference before charging again. }
A GET is retried, up to ClientOptions::$maxRetries times with a doubling delay, after a network error, a
timeout or an error the API marks retryable. Nothing else is retried: the API has no idempotency keys, so a
retried charge could charge twice.
Webhooks
payFURL signs each webhook with the account's webhook signing key (the portal's Webhook Secret Key) and sends the
signature in X-Payfurl-Signature. Check it before trusting the body:
use payFURL\Sdk\Model\ChargeData; use payFURL\Sdk\Webhook; $body = file_get_contents('php://input'); $event = Webhook::parse($body, $_SERVER['HTTP_X_PAYFURL_SIGNATURE'] ?? null, $signingKey); // throws if it is not payFURL's if ($event['meta']['type'] === 'transaction') { $charge = ChargeData::fromArray($event['data']); }
Webhook::verify() returns a bool instead. Both compare in constant time.
Testing your code
FakeTransport stands in for the network: queue the API's responses, then check what your code sent.
use payFURL\Sdk\ClientOptions; use payFURL\Sdk\Http\FakeTransport; $transport = (new FakeTransport())->queue(201, ['chargeId' => 'ch1', 'status' => 'SUCCESS']); $payfurl = new PayfurlClient('sectest0-au', Environment::Sandbox, new ClientOptions(transport: $transport)); $checkout->pay($payfurl); // your code $transport->lastRequest()->url; // https://sandbox-api-au.payfurl.com/charge/token $transport->lastBody()['amount']; // 20.0
queueFailure() makes the next request fail as a network error or a timeout. Any other Transport works too,
such as one that logs each request before handing it to CurlTransport.
Development
just runs the checks:
just test # PHPUnit, PHPStan (max level), PHP CS Fixer (PER-CS), composer validate and audit just fix # apply the code style
The unit tests (tests/Unit) never call an API: each request goes through FakeTransport, so they need no payFURL
account. payFURL runs integration tests against its API before each release.
License
MIT, see LICENSE.