{"id":21599172,"url":"https://github.com/gridonic/swisscom-easypay","last_synced_at":"2025-03-18T11:41:36.837Z","repository":{"id":32568652,"uuid":"135997207","full_name":"gridonic/swisscom-easypay","owner":"gridonic","description":"PHP library to handle payments with Swisscom EasyPay","archived":false,"fork":false,"pushed_at":"2022-06-22T06:12:10.000Z","size":77,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-24T17:47:18.449Z","etag":null,"topics":["easypay","library","php","swisscom"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gridonic.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-04T08:50:43.000Z","updated_at":"2022-05-27T19:36:30.000Z","dependencies_parsed_at":"2022-09-20T18:33:38.427Z","dependency_job_id":null,"html_url":"https://github.com/gridonic/swisscom-easypay","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gridonic%2Fswisscom-easypay","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gridonic%2Fswisscom-easypay/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gridonic%2Fswisscom-easypay/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gridonic%2Fswisscom-easypay/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gridonic","download_url":"https://codeload.github.com/gridonic/swisscom-easypay/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244216699,"owners_count":20417650,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["easypay","library","php","swisscom"],"created_at":"2024-11-24T18:14:31.997Z","updated_at":"2025-03-18T11:41:36.811Z","avatar_url":"https://github.com/gridonic.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Swisscom Easypay\n\nA PHP library to manage payments with Swisscom Easypay.\n\n[![Build Status](https://travis-ci.org/gridonic/swisscom-easypay.svg?branch=master)](https://travis-ci.org/gridonic/swisscom-easypay)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n## Installation\n\nInstall the library with composer: \n\n```\ncomposer require gridonic/swisscom-easypay\n```\n\n## Basic Usage\n\nNote: This guide only covers the basics on how to use this library. More details about Easypay can be found\nin the [official documentations](https://www.swisscom.ch/en/business/enterprise/offer/value-added-services/business-numbers/technische-dokumentation-business-numbers.html).\n\n### Environment\n\nCreate a new `STAGING` or `PROD` environment based on your credentials:\n\n```php\nuse Gridonic\\EasyPay\\Environment\\Environment;\n\n$prodEnvironment = new Environment(Environment::ENV_PROD, 'my-merchant-id', 'my-secret-key')\n$stagingEnvironment = new Environment(Environment::ENV_STAGING, 'my-merchant-id', 'my-secret-key')\n```\n\n### Checkout page\n\nRedirect the user to the Easypay checkout page where the purchase must be confirmed.\n\n1. Map the user's shopping cart to a `CheckoutPageItem`. Note that you must provide the \n_success/error/cancel_ urls for the redirect back to your shop.\n2. In case of a recurrent service, make sure to pass the duration and duration unit to\n the checkout page item via `setDuration()` and `setDurationUnit()`. \n3. Call `CheckoutPageService::getCheckoutPageUrl()` to obtain the redirect url.\n\n```php\nuse Gridonic\\EasyPay\\CheckoutPage\\CheckoutPageItem;\nuse Gridonic\\EasyPay\\CheckoutPage\\CheckoutPageService;\n\n// Map the user's shopping cart to a CheckoutPageItem\n$checkoutPageItem = new CheckoutPageItem();\n$checkoutPageItem\n    -\u003esetTitle('A mandatory title displayed on the checkout page')\n    -\u003esetDescription('A mandatory description displayed on the checkout page')\n    -\u003esetPaymentInfo('Mandatory payment information, visible on the invoice of the customer')\n    -\u003esetAmount('99.90')\n    -\u003esetSuccessUrl('https://myshop.com/return')\n    -\u003esetErrorUrl('https://myshop.com/return')\n    -\u003esetCancelUrl('https://myshop.com/cancel');\n\n// Get the checkout page redirect URL\n$checkoutPageService = CheckoutPageService::create($environment);\n$redirectUrl = $checkoutPageService-\u003egetCheckoutPageUrl($checkoutPageItem);\n```\n### Handling the checkout page response\n\nAfter confirming the purchase on the checkout page, the user is redirected back to the shop.\nIn order to complete the purchase, the payment must be committed via Easypay's REST API. Use\nthe `CheckoutPageResponseService` to get the `payment-ID` or `subscription-ID` required to \ncommit the payment:\n\n```php\nuse Gridonic\\EasyPay\\CheckoutPage\\CheckoutPageResponse;\n\n// Create an instance from the available GET parameters\n$checkoutPageResponse = CheckoutPageResponse::createFromGet();\n\nif ($checkoutPageResponse-\u003eisSuccess()) {\n    $paymentId = $checkoutPageResponse-\u003egetPaymentId();\n    \n    // or if the submitted CheckoutPageItem is a subscription (recurrent service)\n    $authSubscriptionId = $checkoutPageResponse-\u003egetAuthSubscriptionId();\n} else {\n    print_r($checkoutPageResponse-\u003egetErrorCode());\n}\n```\n\n### Commit payments\n\nOne-time (direct) payments need to be committed via Easypay's REST API.\nUse the `RestApiService` to do so:\n\n```php\nuse Gridonic\\EasyPay\\REST\\RESTApiService;\n\n$restApiService = RESTApiService::create($environment);\n\n// Commit a direct payment\n$directPaymentResponse = $restApiService-\u003edirectPayment('paymentId');\n\nif ($directPaymentResponse-\u003eisSuccess()) {\n    // Payment commited successfully\n} else {\n    // A more detailed error is available as error message:\n    $errorMessages = $directPaymentResponse-\u003egetErrorMessages();\n    $errorMessage = array_pop($errorMessages);\n    $errorMessage-\u003egetMessage();\n    $errorMessage-\u003egetCode();\n    $errorMessage-\u003egetField();\n    $errorMessage-\u003egetRequestId();\n}\n```\n\nIn case of a service subscription, the procedure is similar:\n\n```php\n// Authorize a subscription\n$authSubscriptionResponse = $restApiService-\u003eauthorizeSubscription('authSubscriptionId');\n\nif ($authSubscriptionResponse-\u003eisSuccess()) {\n    // Subscription authorized successfully\n} else {\n    $errorMessages = $authSubscriptionResponse-\u003egetErrorMessages();\n    $errorMessage = array_pop($errorMessages);\n    // ...accessing the error details is identical to the direct payment example above\n}\n```\n\n## Easypay REST API\n\nThe `RestApiService` class offers an abstraction of Easypay's REST API to manage payments.\n\n---\n\n**`directPayment(string $paymentId, $operation = 'COMMIT') : DirectPaymentResponse`**\n\nCommit/Reject or Refund a direct payment.\n* Available operations: `COMMIT`, `REJECT`, or `REFUND`.\n\n---\n\n**`getDirectPayment(string $paymentId) : DirectPaymentResponse`**\n\nGet all information about a direct payment.\n\n---\n\n**`authorizeSubscription(string $authSubscriptionId, $operation = 'COMMIT') : AuthSubscriptionResponse`**\n\nCommit/Reject/Refund/Renew or Cancel an authorized subscription.\n* Available operations: `COMMIT`, `REJECT`, `REFUND`, `RENEW` or `CANCEL`.\n\n---\n\n**`getAuthorizeSubscription(string $authSubscriptionId) : AuthSubscriptionResponse`**\n\nGet all information about an authorized subscription.\n\n---\n\n## Run tests\n\nMake sure that the `dev-dependencies` are installed, then execute phpunit from the `vendor` directory:\n\n```\nvendor/bin/phpunit tests\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgridonic%2Fswisscom-easypay","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgridonic%2Fswisscom-easypay","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgridonic%2Fswisscom-easypay/lists"}