PHPackages                             gridonic/swisscom-easypay - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. gridonic/swisscom-easypay

ActiveLibrary

gridonic/swisscom-easypay
=========================

PHP library to handle payments with Swisscom EasyPay

v1.0.1(3y ago)01791MITPHPPHP &gt;=7.0

Since Jun 12Pushed 3y ago4 watchersCompare

[ Source](https://github.com/gridonic/swisscom-easypay)[ Packagist](https://packagist.org/packages/gridonic/swisscom-easypay)[ Docs](https://github.com/gridonic/swisscom-easypay)[ RSS](/packages/gridonic-swisscom-easypay/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

Swisscom Easypay
================

[](#swisscom-easypay)

A PHP library to manage payments with Swisscom Easypay.

[![Build Status](https://camo.githubusercontent.com/a5521c3879658ea5133dece3ade4024b7caed849d6f275dbbaae8c6871c5b6ba/68747470733a2f2f7472617669732d63692e6f72672f677269646f6e69632f7377697373636f6d2d656173797061792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/gridonic/swisscom-easypay)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)

Installation
------------

[](#installation)

Install the library with composer:

```
composer require gridonic/swisscom-easypay

```

Basic Usage
-----------

[](#basic-usage)

Note: This guide only covers the basics on how to use this library. More details about Easypay can be found in the [official documentations](https://www.swisscom.ch/en/business/enterprise/offer/value-added-services/business-numbers/technische-dokumentation-business-numbers.html).

### Environment

[](#environment)

Create a new `STAGING` or `PROD` environment based on your credentials:

```
use Gridonic\EasyPay\Environment\Environment;

$prodEnvironment = new Environment(Environment::ENV_PROD, 'my-merchant-id', 'my-secret-key')
$stagingEnvironment = new Environment(Environment::ENV_STAGING, 'my-merchant-id', 'my-secret-key')
```

### Checkout page

[](#checkout-page)

Redirect the user to the Easypay checkout page where the purchase must be confirmed.

1. Map the user's shopping cart to a `CheckoutPageItem`. Note that you must provide the *success/error/cancel* urls for the redirect back to your shop.
2. In case of a recurrent service, make sure to pass the duration and duration unit to the checkout page item via `setDuration()` and `setDurationUnit()`.
3. Call `CheckoutPageService::getCheckoutPageUrl()` to obtain the redirect url.

```
use Gridonic\EasyPay\CheckoutPage\CheckoutPageItem;
use Gridonic\EasyPay\CheckoutPage\CheckoutPageService;

// Map the user's shopping cart to a CheckoutPageItem
$checkoutPageItem = new CheckoutPageItem();
$checkoutPageItem
    ->setTitle('A mandatory title displayed on the checkout page')
    ->setDescription('A mandatory description displayed on the checkout page')
    ->setPaymentInfo('Mandatory payment information, visible on the invoice of the customer')
    ->setAmount('99.90')
    ->setSuccessUrl('https://myshop.com/return')
    ->setErrorUrl('https://myshop.com/return')
    ->setCancelUrl('https://myshop.com/cancel');

// Get the checkout page redirect URL
$checkoutPageService = CheckoutPageService::create($environment);
$redirectUrl = $checkoutPageService->getCheckoutPageUrl($checkoutPageItem);
```

### Handling the checkout page response

[](#handling-the-checkout-page-response)

After confirming the purchase on the checkout page, the user is redirected back to the shop. In order to complete the purchase, the payment must be committed via Easypay's REST API. Use the `CheckoutPageResponseService` to get the `payment-ID` or `subscription-ID` required to commit the payment:

```
use Gridonic\EasyPay\CheckoutPage\CheckoutPageResponse;

// Create an instance from the available GET parameters
$checkoutPageResponse = CheckoutPageResponse::createFromGet();

if ($checkoutPageResponse->isSuccess()) {
    $paymentId = $checkoutPageResponse->getPaymentId();

    // or if the submitted CheckoutPageItem is a subscription (recurrent service)
    $authSubscriptionId = $checkoutPageResponse->getAuthSubscriptionId();
} else {
    print_r($checkoutPageResponse->getErrorCode());
}
```

### Commit payments

[](#commit-payments)

One-time (direct) payments need to be committed via Easypay's REST API. Use the `RestApiService` to do so:

```
use Gridonic\EasyPay\REST\RESTApiService;

$restApiService = RESTApiService::create($environment);

// Commit a direct payment
$directPaymentResponse = $restApiService->directPayment('paymentId');

if ($directPaymentResponse->isSuccess()) {
    // Payment commited successfully
} else {
    // A more detailed error is available as error message:
    $errorMessages = $directPaymentResponse->getErrorMessages();
    $errorMessage = array_pop($errorMessages);
    $errorMessage->getMessage();
    $errorMessage->getCode();
    $errorMessage->getField();
    $errorMessage->getRequestId();
}
```

In case of a service subscription, the procedure is similar:

```
// Authorize a subscription
$authSubscriptionResponse = $restApiService->authorizeSubscription('authSubscriptionId');

if ($authSubscriptionResponse->isSuccess()) {
    // Subscription authorized successfully
} else {
    $errorMessages = $authSubscriptionResponse->getErrorMessages();
    $errorMessage = array_pop($errorMessages);
    // ...accessing the error details is identical to the direct payment example above
}
```

Easypay REST API
----------------

[](#easypay-rest-api)

The `RestApiService` class offers an abstraction of Easypay's REST API to manage payments.

---

**`directPayment(string $paymentId, $operation = 'COMMIT') : DirectPaymentResponse`**

Commit/Reject or Refund a direct payment.

- Available operations: `COMMIT`, `REJECT`, or `REFUND`.

---

**`getDirectPayment(string $paymentId) : DirectPaymentResponse`**

Get all information about a direct payment.

---

**`authorizeSubscription(string $authSubscriptionId, $operation = 'COMMIT') : AuthSubscriptionResponse`**

Commit/Reject/Refund/Renew or Cancel an authorized subscription.

- Available operations: `COMMIT`, `REJECT`, `REFUND`, `RENEW` or `CANCEL`.

---

**`getAuthorizeSubscription(string $authSubscriptionId) : AuthSubscriptionResponse`**

Get all information about an authorized subscription.

---

Run tests
---------

[](#run-tests)

Make sure that the `dev-dependencies` are installed, then execute phpunit from the `vendor` directory:

```
vendor/bin/phpunit tests

```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 62.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1470 days

Total

2

Last Release

1417d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/69c454b52e9a2d5092d96b625d9a692eacdef5079a92af73107f184fc0369aaf?d=identicon)[gridonic](/maintainers/gridonic)

---

Top Contributors

[![wanze](https://avatars.githubusercontent.com/u/2118742?v=4)](https://github.com/wanze "wanze (5 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")

---

Tags

easypaylibraryphpswisscomlibrarypayment gatewayswisscom easypay

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gridonic-swisscom-easypay/health.svg)

```
[![Health](https://phpackages.com/badges/gridonic-swisscom-easypay/health.svg)](https://phpackages.com/packages/gridonic-swisscom-easypay)
```

###  Alternatives

[nutgram/nutgram

The Telegram bot library that doesn't drive you nuts

714214.9k8](/packages/nutgram-nutgram)[shetabit/multipay

PHP Payment Gateway Integration Package

291348.2k3](/packages/shetabit-multipay)[checkout/checkout-sdk-php

Checkout.com SDK for PHP

553.3M7](/packages/checkout-checkout-sdk-php)[imagekit/imagekit

PHP library for Imagekit

47795.6k9](/packages/imagekit-imagekit)[nkl-kst/the-sports-db

PHP library to get sports data from TheSportsDB (https://www.thesportsdb.com)

271.2k](/packages/nkl-kst-the-sports-db)[karson/mpesa-php-sdk

172.2k](/packages/karson-mpesa-php-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
