Download the PHP package amzad/apple-pay-knet without Composer
On this page you can find all versions of the php package amzad/apple-pay-knet. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package apple-pay-knet
amzad/apple-pay-knet
Apple Pay on the Web + KNET Direct integration for Laravel.
Designed for Kuwaiti merchants who want to accept Apple Pay payments through the KNET payment gateway with minimal setup.
Table of Contents
- Requirements
- Installation
- Apple Pay Setup
- Configuration
- Database Migration
- Publishing Assets
- Environment Variables
- Frontend Integration
- Handling the Callback
- Using the Facade
- API Endpoints
- Transaction Model
- Exception Handling
- Sandbox vs Production
- Troubleshooting
Requirements
- PHP
^7.4or^8.0 - Laravel
^8.0|^9.0|^10.0|^11.0|^12.0 - PHP extensions:
curl,openssl,json - An Apple Developer account with Apple Pay enabled
- An Apple Pay Merchant Identity Certificate (
.pem) - A KNET merchant account with API credentials
- Your site must be served over HTTPS with a registered Apple Pay domain
Installation
Step 1 — Install the package via Composer
Step 2 — Auto-discovery (Laravel 8+)
Laravel will automatically register the service provider and facade via package auto-discovery. No manual registration is required.
If you have disabled auto-discovery, add the following to your config/app.php:
Apple Pay Setup
Before any code runs, you must complete the Apple Pay merchant setup. These steps are required and must be done in order.
Step 1 — Enroll in the Apple Developer Program
Go to developer.apple.com and ensure you have an active paid developer account.
Step 2 — Create a Merchant ID
- In the Apple Developer portal, go to Certificates, Identifiers & Profiles → Identifiers.
- Click + and select Merchant IDs.
- Enter a description and identifier (e.g.
merchant.com.yourstore). - Click Register.
Step 3 — Register your domain
- In the Apple Developer portal, open your Merchant ID.
- Under Apple Pay on the Web, click Add Domain.
- Download the domain verification file Apple provides.
-
Place it at this exact path on your server:
- Click Verify in the developer portal.
The file must be accessible without redirect or authentication.
Step 4 — Create a Merchant Identity Certificate
- In the Apple Developer portal, open your Merchant ID.
- Under Merchant Identity Certificate, click Create Certificate.
-
Generate a CSR (Certificate Signing Request) on your server:
- Upload the
.csrfile to Apple and download the resulting.cerfile.
Step 5 — Convert the certificate to PEM format
Apple issues .cer files in DER format. Convert it:
Step 6 — Store certificates securely
- Store
merchant.pemandmerchant.keyoutside your web root (e.g./etc/ssl/apple-pay/). - Set restrictive permissions:
Configuration
Step 1 — Publish the config file
This creates config/apple-pay-knet.php.
Step 2 — Review the config file
Database Migration
Step 1 — Publish the migration
Step 2 — Run the migration
This creates the apple_pay_transactions table with the following columns:
| Column | Type | Description |
|---|---|---|
id |
bigint | Auto-increment primary key |
order_id |
string | Your order/reference ID |
amount |
string | KWD amount as decimal string (e.g. "5.250") |
currency |
string | ISO 4217 numeric code (414 = KWD) |
apple_transaction_id |
string (nullable) | Apple Pay transaction identifier |
knet_transaction_id |
string (nullable) | KNET transaction ID |
status |
enum | pending, authorized, captured, failed |
response_code |
string (nullable) | KNET result code |
auth_code |
string (nullable) | KNET authorization code |
raw_response |
json (nullable) | Full KNET response payload |
created_at / updated_at |
timestamps | Laravel timestamps |
Skip this step if you set
'log_transactions' => falsein your config.
Publishing Assets
Publish the JavaScript handler
This copies apple-pay-handler.js to public/vendor/apple-pay-knet/js/. The Blade component references it automatically.
Publish the Blade views (optional)
This copies the views to resources/views/vendor/apple-pay-knet/ so you can customise them.
Environment Variables
Add the following to your .env file:
Replace
KNET_ENDPOINTwith the production URL when going live (provided by your bank).
Frontend Integration
Option A — Blade Component (Recommended)
Step 1 — Publish the JS asset
Step 2 — Add the component to your Blade view
The component automatically:
- Loads the Apple Pay SDK and the
apple-pay-handler.jsscript (once per page) - Shows/hides the button based on device support
- Handles merchant validation and payment processing
Available Component Props
| Prop | Required | Default | Description |
|---|---|---|---|
amount |
Yes | — | Payment amount as a string (e.g. "5.250") |
reference |
Yes | — | Your unique order/reference ID |
callbackUrl |
Yes | — | URL to POST the KNET response to after payment |
label |
No | config('apple-pay-knet.display_name') |
Label shown on the payment sheet |
currencyCode |
No | KWD |
ISO 4217 currency code |
countryCode |
No | KW |
ISO 3166 country code |
paymentGateway |
No | KNET |
Payment gateway identifier |
onSuccess |
No | null |
JavaScript callback function on success |
onError |
No | null |
JavaScript callback function on error |
onCancel |
No | null |
JavaScript callback function on cancel |
Custom JS Callbacks Example
Option B — Manual JavaScript Integration
If you prefer not to use the Blade component, include the scripts manually and initialise ApplePayKnet directly.
Step 1 — Include the scripts
Step 2 — Add the Apple Pay button element
Step 3 — Initialise the handler
Full init options
| Option | Required | Default | Description |
|---|---|---|---|
validateMerchantUrl |
Yes | — | Route to the package's validate-merchant endpoint |
processPaymentUrl |
Yes | — | Route to the package's process-payment endpoint |
amount |
Yes | — | Payment amount string |
reference |
Yes | — | Unique order reference |
callbackUrl |
Yes | — | Your callback URL that receives the KNET response |
csrfToken |
Yes | — | Laravel CSRF token |
label |
No | "Your card will be charged" |
Label on the payment sheet total line |
applePayVersion |
No | 3 |
Apple Pay JS API version |
countryCode |
No | "KW" |
ISO 3166 country code |
currencyCode |
No | "KWD" |
ISO 4217 currency code |
merchantCapabilities |
No | ["supports3DS"] |
Array of merchant capabilities |
supportedNetworks |
No | ["visa", "masterCard", "amex", "discover"] |
Array of supported card networks |
paymentGateway |
No | "KNET" |
Gateway identifier sent to the server |
onSuccess |
No | null |
JS function called on successful authorization |
onError |
No | null |
JS function called on any error |
onCancel |
No | null |
JS function called when the user cancels |
Handling the Callback
After a successful payment, the package auto-submits a hidden form that POSTs the KNET response fields to your callbackUrl. Create a route and controller action to handle this:
Step 1 — Define the route
Step 2 — Handle the callback
Important: Always verify the
resultfield equals"CAPTURED"before marking an order as paid. Do not rely solely on the callback being called.
Using the Facade
You can charge directly from your own controller without going through the package's HTTP endpoints:
charge() method signature
| Parameter | Type | Description |
|---|---|---|
$amount |
string | KWD amount (e.g. "5.250") |
$reference |
string | Your unique order/reference ID |
$applePayment |
array | Full event.payment object from the Apple Pay JS onpaymentauthorized event |
API Endpoints
The package registers the following routes automatically under the configured route_prefix (default: apple-pay):
| Method | URL | Name | Description |
|---|---|---|---|
GET |
/apple-pay/validate-merchant |
apple-pay-knet.validate-merchant |
Validates the merchant session with Apple's servers |
POST |
/apple-pay/process-payment |
apple-pay-knet.process-payment |
Processes the Apple Pay payment through KNET |
POST /apple-pay/process-payment
Request body:
| Field | Type | Required | Description |
|---|---|---|---|
amount |
numeric | Yes | Payment amount (min: 0.001) |
reference |
string | Yes | Unique order reference (max: 255 chars) |
apple_pay_response |
object/string | Yes | Full event.payment object from Apple Pay JS |
payment_gateway |
string | No | Gateway identifier (default: KNET) |
Success response:
Error response:
Changing the route prefix
This changes the routes to /payments/apple/validate-merchant and /payments/apple/process-payment.
Adding custom middleware
Transaction Model
When log_transactions is enabled, you can query the Transaction model directly:
Available scopes
| Scope | Description |
|---|---|
Transaction::successful() |
Filters authorized and captured statuses |
Transaction::failed() |
Filters failed status |
Transaction statuses
| Status | Description |
|---|---|
pending |
Charge initiated, awaiting KNET response |
authorized |
KNET returned a successful authorization |
captured |
Payment captured (set manually in your callback) |
failed |
KNET returned an error or connection failed |
Exception Handling
The package throws two exception types:
ApplePayException
Thrown when Apple merchant validation fails.
KnetException
Thrown when KNET authorization fails or a network error occurs.
Sandbox vs Production
Sandbox (testing)
Use the KNET test endpoint:
Apple Pay requires a real device with a real card even in sandbox mode. Safari on Mac with a linked iPhone/Apple Watch will work.
Production
Replace with your bank-provided production endpoint:
Also update APPLE_PAY_VALIDATION_URL if Apple provides a different production URL:
Troubleshooting
Apple Pay button not showing
- Ensure the page is served over HTTPS.
- Ensure you are using Safari on a compatible Apple device.
- Verify the domain is registered and verified in the Apple Developer portal.
- Check browser console for
[ApplePayKnet]log messages.
Merchant validation returns 400
-
Confirm your certificate is in PEM format (not DER). Run:
- Verify your domain is registered in the Apple Developer portal under the correct Merchant ID.
- Make sure the
.well-known/apple-developer-merchantid-domain-associationfile is publicly accessible. - Check the certificate has not expired.
Certificate errors on boot
The package validates your certificate on every merchant validation call. Common errors and their fixes:
| Error message | Fix |
|---|---|
Certificate file not found or not readable |
Check APPLE_PAY_CERTIFICATE_PATH points to the correct file with read permissions |
Certificate file is not in PEM format |
Convert: openssl x509 -inform DER -in file.cer -out file.pem |
Merchant Identity Certificate expired |
Renew in the Apple Developer portal |
Certificate and private key do not match |
Ensure you use the key that generated the CSR for this specific certificate |
Private key file could not be loaded |
Check APPLE_PAY_CERTIFICATE_KEY_PATH and APPLE_PAY_CERTIFICATE_KEY_PASSWORD |
KNET returns no trackid
- Verify
KNET_IDandKNET_PASSWORDare correct. - Ensure
KNET_RESPONSE_URLandKNET_ERROR_URLare publicly accessible HTTPS URLs. - Check you are using the correct endpoint (sandbox vs production).
CSRF token mismatch
- Ensure
csrfTokenis passed in the JS init config. - The Blade component handles this automatically via
{{ csrf_token() }}. - If using the API from a SPA, include the
X-CSRF-TOKENheader or use a Sanctum token.
License
This package is open-sourced software licensed under the MIT license.
Author
Amzad — [email protected]
All versions of apple-pay-knet with dependencies
illuminate/support Version ^8.0|^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/http Version ^8.0|^9.0|^10.0|^11.0|^12.0|^13.0
ext-curl Version *
ext-openssl Version *
ext-json Version *