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.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

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.

Latest Version on Packagist


Table of Contents

  1. Requirements
  2. Installation
  3. Apple Pay Setup
  4. Configuration
  5. Database Migration
  6. Publishing Assets
  7. Environment Variables
  8. Frontend Integration
  9. Handling the Callback
  10. Using the Facade
  11. API Endpoints
  12. Transaction Model
  13. Exception Handling
  14. Sandbox vs Production
  15. Troubleshooting

Requirements


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

  1. In the Apple Developer portal, go to Certificates, Identifiers & Profiles → Identifiers.
  2. Click + and select Merchant IDs.
  3. Enter a description and identifier (e.g. merchant.com.yourstore).
  4. Click Register.

Step 3 — Register your domain

  1. In the Apple Developer portal, open your Merchant ID.
  2. Under Apple Pay on the Web, click Add Domain.
  3. Download the domain verification file Apple provides.
  4. Place it at this exact path on your server:

  5. Click Verify in the developer portal.

The file must be accessible without redirect or authentication.

Step 4 — Create a Merchant Identity Certificate

  1. In the Apple Developer portal, open your Merchant ID.
  2. Under Merchant Identity Certificate, click Create Certificate.
  3. Generate a CSR (Certificate Signing Request) on your server:

  4. Upload the .csr file to Apple and download the resulting .cer file.

Step 5 — Convert the certificate to PEM format

Apple issues .cer files in DER format. Convert it:

Step 6 — Store certificates securely


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' => false in 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_ENDPOINT with 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:

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 result field 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

Merchant validation returns 400

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

CSRF token mismatch


License

This package is open-sourced software licensed under the MIT license.


Author

Amzad[email protected]


All versions of apple-pay-knet with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4|^8.0
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 *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package amzad/apple-pay-knet contains the following files

Loading the files please wait ...