{"id":19450896,"url":"https://github.com/morning-train/wp-nets-easy","last_synced_at":"2025-04-25T03:32:10.635Z","repository":{"id":65151497,"uuid":"584342681","full_name":"Morning-Train/wp-nets-easy","owner":"Morning-Train","description":"Nets Easy implementation for WordPress (SDK) ","archived":false,"fork":false,"pushed_at":"2024-03-26T11:16:34.000Z","size":43,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-03T15:43:52.529Z","etag":null,"topics":["nets","payment","payments","php","wordpress","wp"],"latest_commit_sha":null,"homepage":"","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/Morning-Train.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-02T09:44:11.000Z","updated_at":"2023-08-01T20:37:45.000Z","dependencies_parsed_at":"2024-11-10T16:40:49.021Z","dependency_job_id":null,"html_url":"https://github.com/Morning-Train/wp-nets-easy","commit_stats":{"total_commits":20,"total_committers":1,"mean_commits":20.0,"dds":0.0,"last_synced_commit":"71666a3652284b293d64ced2761a23920f06b60d"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morning-Train%2Fwp-nets-easy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morning-Train%2Fwp-nets-easy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morning-Train%2Fwp-nets-easy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morning-Train%2Fwp-nets-easy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Morning-Train","download_url":"https://codeload.github.com/Morning-Train/wp-nets-easy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250748109,"owners_count":21480780,"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":["nets","payment","payments","php","wordpress","wp"],"created_at":"2024-11-10T16:39:23.021Z","updated_at":"2025-04-25T03:32:10.099Z","avatar_url":"https://github.com/Morning-Train.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Morningtrain\\WpNetsEasy\n\nA Morningtrain package to simple handle NETS Easy payments.\n\n## Table of Contents\n\n- [Introduction](#introduction)\n- [Getting Started](#getting-started)\n    - [Installation](#installation)\n- [Dependencies](#dependencies)\n    - [illuminate/database](#illuminatedatabase)\n- [Usage](#usage)\n    - [Initializing package](#initializing-package)\n    - [Create payment](#create-payment)\n    - [Handle existing payment](#handle-existing-payment)\n    - [Create subscription](#create-subscription)\n    - [Handle existing subscription](#handle-existing-subscription)\n    - [Handle webhooks](#handle-webhooks)\n- [Credits](#credits)\n- [Testing](#testing)\n- [License](#license)\n\n## Introduction\n\n## Getting Started\n\nTo get started install the package as described below in [Installation](#installation).\n\nTo use the tool have a look at [Usage](#usage)\n\n### Installation\n\nInstall with composer\n\n```bash\ncomposer require morningtrain/wp-nets-easy\n```\n\n## Dependencies\n\n- [morningtrain/wp-route](https://packagist.org/packages/morningtrain/wp-route)\n- [morningtrain/wp-database](https://packagist.org/packages/morningtrain/wp-database)\n- [morningtrain/php-loader](https://packagist.org/packages/morningtrain/php-loader)\n\n## Usage\n\n### Initializing package\n\nInitialize `\\Morningtrain\\WpNetsEasy\\NetsEasy` with NETS Easy test or live secret key.\n\n```php\n\\Morningtrain\\WpNetsEasy\\NetsEasy::init('live-secret-key-abcdefghijklmnopqrstuvwxyz123456789');\n```\n\n### Running migrations\n\nThis needs to be done before using the package, or after updating the package.  \nYou can run all new migrations like so:\n\nUsing `wp cli`:\n\n```shell\nwp dbmigrate\n```\n\nUsing `php`:\n\n```php\n\u003c?php\n    \\Morningtrain\\WP\\Database\\Database::migrate();\n?\u003e\n```\n\n### Create payment\n\n```php\nuse Morningtrain\\WpNetsEasy\\Classes\\Payment\\Payment;\nuse Morningtrain\\WpNetsEasy\\Classes\\Payment\\Customer;\nuse Morningtrain\\WpNetsEasy\\Classes\\Payment\\Address;\nuse Morningtrain\\WpNetsEasy\\Classes\\Payment\\Item;\n\n// Create payment and set payment information and urls\n$payment = Payment::create()\n    -\u003esetReference($orderId)\n    -\u003esetCustomer(\n        Customer::create()\n            -\u003esetReference($customer-\u003eid)\n            -\u003esetEmail($customer-\u003eemail)\n            -\u003esetPhone($customer-\u003ephone)\n            -\u003esetName($customer-\u003efirstName, $customer-\u003elastName)\n            -\u003esetCompanyName($customer-\u003ecompanyName)\n            -\u003esetShippingAddress(\n                Address::create()\n                    -\u003esetAddressLine1($customer-\u003eaddress1)\n                    -\u003esetAddressLine2($customer-\u003eaddress2)\n                    -\u003esetPostalCode($customer-\u003ezipCode)\n                    -\u003esetCity($customer-\u003ecity())\n            )\n        )\n    -\u003esetTermsUrl(get_post_permalink($termsPageId))\n    -\u003esetReturnUrl(Route::route('payment-success', ['token' =\u003e $order-\u003etoken]))\n    -\u003esetCancelUrl(Route::route('payment-cancel', ['token' =\u003e $order-\u003etoken]));\n\n// Add items to payments\nforeach($order-\u003eitems as $item) {\n    $payment-\u003eaddItem(\n        Item::create($item-\u003esku)\n            -\u003esetName($item-\u003ename)\n            -\u003esetQuantity($item-\u003equantity)\n            -\u003esetUnitPriceInclusiveTax($item-\u003eprice)\n    );\n}\n\n// Persist payment in NETS Easy\n$response = $payment-\u003ecreateRequest();\n\nif(wp_remote_retrieve_response_code($response) !== 201) {\n    // Error handling when something was wrong with the payment\n    wp_redirect($checkoutUrl);\n    exit();\n}\n\n// Save payment reference to order\n$order-\u003esetPaymentId($payment-\u003egetPaymentId());\n\n// Redirect to payment page\nwp_redirect($payment-\u003egetPaymentPageUrl());\nexit();\n```\n\n#### Auto charge payment\nIf your product allows you to auto charge payment. You can tell Nets Easy to charge the payment automatically before you persist the payment.\n\n```php\n$payment-\u003eautoCharge()\n```\n\n### Handle existing payment\nWhen a payment requrest has been created, the payment reference will be saved to the database.\n\n#### Get payment\nPayment is a model implementet with Eloquent. \nTo get payments you can use all methods from Eloquent (see [documentation](https://laravel.com/docs/9.x/eloquent#retrieving-models)).\n\nYou can use the custom method ```Payment::getByPaymentId($paymentId);```\n\n```php\n$payment = Payment::getByPaymentId($order-\u003epayment_id);\n```\n\n#### Terminate payment\nTo terminate payment, the customer must not have finished checkout.\nYou can use it on the cancel callback to avoid double payments later.\n\n```php\n$payment-\u003eterminate()\n```\n\n#### Check if payment is reserved\n\n```php\n$payment-\u003eisReserved()\n```\n\n#### Check if payment is charged\n\n```php\n$payment-\u003eisCharged()\n```\n\n#### Charge payment\n\n```php\n$payment-\u003echarge()\n```\n\n*NOTE: Partly charges is not implementet yet*\n\n#### Refund payment\n\n*NOTE: Refund and partly refund is not implementet yet*\n\n### Create subscription\n\n*NOTE: Subscriptions is not implementet yet*\n\n### Handle existing subscription\n\n*NOTE: Subscriptions is not implementet yet*\n\n### Handle webhoks\nThe implementation handle webhooks and sets the payment status automatically.\n\nIf you need to do something on a specific webhook, you can do that throug actions and filters.\n\n#### List of implemented webhooks\n\n| Name                        | Descritpion                                                     |\n|-----------------------------|-----------------------------------------------------------------|\n| payment.created             | A payment has been created.                                     |\n| payment.reservation.created | The amount of the payment has been reserved.                    |\n| payment.reservation.failed  | A reservation attempt has failed.                               |\n| payment.checkout.completed  | The customer has completed the checkout.                        |\n| payment.charge.created.v2   | The customer has successfully been charged, partially or fully. |\n| payment.charge.failed       | A charge attempt has failed.                                    |\n| payment.refund.initiated.v2 | A refund has been initiated.                                    |\n| payment.refund.failed       | A refund attempt has failed.                                    |\n| payment.refund.completed    | A refund has successfully been completed.                       |\n| payment.cancel.created      | A reservation has been canceled.                                |\n| payment.cancel.failed       | A cancellation has failed.                                      |\n\n#### Actions\n\n| Hook Name                                     | Description                                                                                                   |\n|-----------------------------------------------|---------------------------------------------------------------------------------------------------------------|\n| morningtrain/nets-easy/webhook/{$webhookName} | Do something on the webhook (before the implementet handling but after we have checked for previous handling) |\n\n#### Filters\n| Hook Name                                                  | Filtered value                                    | Extra parameters                        | Description                                                                                                          |\n|------------------------------------------------------------|---------------------------------------------------|-----------------------------------------|----------------------------------------------------------------------------------------------------------------------|\n| morningtrain/nets-easy/webhook/{$webhookName}/bypass       | false                                             | none                                    | Return something to bypass all webhook handling logic                                                                |\n| morningtrain/nets-easy/webhook/{$webhookName}/after-handle | false or value from handle function               | $webhook - The Webhook object with data | Do something after default handling. Return something to bypass setting the webhook as handled and return status 200 |\n| morningtrain/nets-easy/webhook/{$webhookName}/response     | WP_REST_Response with default values (status 200) | $webhook - The Webhook object with data | Filter the response after webhook fully handled                                                                      |\n\n## Credits\n\n- [Martin Schadegg Brønniche](https://github.com/mschadegg)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorning-train%2Fwp-nets-easy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmorning-train%2Fwp-nets-easy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorning-train%2Fwp-nets-easy/lists"}