{"id":19854724,"url":"https://github.com/phwoolcon/payment","last_synced_at":"2026-05-14T19:34:54.527Z","repository":{"id":57041239,"uuid":"61515756","full_name":"phwoolcon/payment","owner":"phwoolcon","description":"Payment module for Phwoolcon","archived":false,"fork":false,"pushed_at":"2017-07-30T08:29:01.000Z","size":62,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-11T13:50:56.603Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phwoolcon.png","metadata":{"files":{"readme":"README-zh.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}},"created_at":"2016-06-20T04:00:55.000Z","updated_at":"2016-06-20T04:05:35.000Z","dependencies_parsed_at":"2022-08-23T23:30:46.773Z","dependency_job_id":null,"html_url":"https://github.com/phwoolcon/payment","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phwoolcon%2Fpayment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phwoolcon%2Fpayment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phwoolcon%2Fpayment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phwoolcon%2Fpayment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phwoolcon","download_url":"https://codeload.github.com/phwoolcon/payment/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241245040,"owners_count":19933295,"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":[],"created_at":"2024-11-12T14:10:13.978Z","updated_at":"2026-05-14T19:34:54.477Z","avatar_url":"https://github.com/phwoolcon.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Phwoolcon Payment\n[![Build Status](https://travis-ci.org/phwoolcon/payment.svg?branch=master)](https://travis-ci.org/phwoolcon/payment)\n[![Code Coverage](https://codecov.io/gh/phwoolcon/payment/branch/master/graph/badge.svg)](https://codecov.io/gh/phwoolcon/payment)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\nPhwoolcon 支付模块\n\n本模块已默认集成支付宝。\n\n## 1. 安装\n用 composer 把本模块加入到你的项目中：\n\n```\ncomposer require \"phwoolcon/payment\":\"dev-master\"\n```\n\n## 2. 配置\n请创建文件 `app/config/production/payment.php` 来填写支付宝收款帐号：\n```php\n\u003c?php\nreturn [\n    'gateways' =\u003e [\n        'alipay' =\u003e [\n            'partner' =\u003e 'YOUR_PARTNER_ID_APPLIED_FROM_ALIPAY',\n            'seller_id' =\u003e 'YOUR_SELLER_EMAIL_APPLIED_FROM_ALIPAY',\n            'private_key' =\u003e '-----BEGIN RSA PRIVATE KEY-----\nYOUR_PRIVATE_KEY_PROVIDED_TO_ALIPAY\n-----END RSA PRIVATE KEY-----',\n            'ali_public_key' =\u003e '-----BEGIN PUBLIC KEY-----\nTHE_PUBLIC_KEY_APPLIED_FROM_ALIPAY\n-----END PUBLIC KEY-----',\n        ],\n    ],\n];\n\n```\n\n## 3. 使用\n\nPhwoolcon Payment 抽象了一个支付处理器，所有支付动作都将通过 `Processor::run()`  \n来调用。\n\n### 3.1. 发送支付宝支付请求（手机 Web 支付）\n```php\n\u003c?php\nuse Phalcon\\Di;\nuse Phwoolcon\\Payment\\Processor;\n\n$di = Di::getDefault();\nProcessor::register($di);\n\n$tradeId = md5(microtime());\n$payload = Processor::run(Payload::create([\n    'gateway' =\u003e 'alipay',\n    'method' =\u003e 'mobile_web',\n    'action' =\u003e 'payRequest',\n    'data' =\u003e [\n        'trade_id' =\u003e $tradeId,\n        'product_name' =\u003e 'Test product',\n        'client_id' =\u003e 'test_client',\n        'user_identifier' =\u003e 'Test User',\n        'amount' =\u003e 1,\n    ],\n]));\necho get_class($payload);       // 输出 Phwoolcon\\Payment\\Process\\Payload\n\n$result = $payload-\u003egetResult();\necho get_class($result);        // 输出 Phwoolcon\\Payment\\Process\\Result\n\n$order = $result-\u003egetOrder();\necho get_class($order);         // 输出 Phwoolcon\\Payment\\Model\\Order\n\necho $order-\u003egetStatus();       // 输出 pending\n\n$redirectUrl = $order-\u003egetPaymentGatewayUrl();\necho $redirectUrl;              // 输出类似这样的 url：\n                                // https://mapi.alipay.com/gateway.do?service=alipay.wap.create.direct.pay.by.user\u0026partner=...\n                                // 你可以一个用 302 响应把用户浏览器重定向\n                                // 到这个 url 以完成支付\n\n$returnUrl = $order-\u003egetOrderData('alipay_request.return_url');\necho $returnUrl;                // 输出类似这样的 url：\n                                // http://yoursite.com/api/alipay/return\n                                // 支付成功或失败后，支付宝会把用户跳转到\n                                // 这个 url\n\n$notifyUrl = $order-\u003egetOrderData('alipay_request.notify_url');\necho $notifyUrl;                // 输出类似这样的 url：\n                                // http://yoursite.com/api/alipay/callback\n                                // 支付成功或失败后，支付宝服务器会对这个\n                                // url 发起 post 回调\n```\n\n### 3.2. 处理支付宝回调\n```php\n\u003c?php\nuse Phalcon\\Di;\nuse Phwoolcon\\Payment\\Processor;\n\n$di = Di::getDefault();\nProcessor::register($di);\n$payload = Processor::run(Payload::create([\n    'gateway' =\u003e 'alipay',\n    'method' =\u003e 'mobile_web',\n    'action' =\u003e 'callback',\n    'data' =\u003e $_POST,\n]));\n$result = $payload-\u003egetResult();\necho $result-\u003egetResponse();    // 输出 success\n```\n\n## 4. 如何创建自定义支付方式\n所有支付方式都是在配置文件 `payment.php` 里定义的，如果有需要，你可以添加  \n任何支付网关/支付方式。\n\n### 4.1. 创建支付网关/支付方式配置结构\n编辑 `app/config/payment.php`:\n```php\n\u003c?php\nreturn [\n    'gateways' =\u003e [\n\n        .\n        .\n        .\n\n        'your_gateway' =\u003e [\n            'label' =\u003e '支付网关名称',\n            'order_prefix' =\u003e 'SOME_PREFIX',\n            'methods' =\u003e [\n                'payment_method_1' =\u003e [\n                    'class' =\u003e 'Fully\\Qualified\\Class\\Name',\n                    'label' =\u003e '支付方式名称',\n                ],\n                'payment_method_2' =\u003e [\n                    'class' =\u003e 'Fully\\Qualified\\Class\\Name',\n                    'label' =\u003e '支付方式名称',\n                ],\n            ],\n            'required_callback_parameters' =\u003e [\n                'order_id',\n                'amount',\n                'status',\n                'sign',\n            ],\n            'any_options' =\u003e 'value',\n            'another_option' =\u003e 'value',\n        ],\n    ],\n];\n```\n\n### 4.2. 填写真实帐号资料\n请**不要**在上面的配置文件里面填写真实帐号资料，假如你把这个文件添加到版本  \n控制系统（例如 git，svn），你的支付网关帐号可能会被泄露。\n\n正确的做法是，把真实帐号填写到 `app/config/production/payment.php` 文件中，  \n并且在版本控制系统里面忽略这个文件。\n\n### 4.3. 创建支付方式类\n支付方式类**必须**实现接口 `Phwoolcon\\Payment\\MethodInterface`\n\n`Phwoolcon\\Payment\\MethodTrait` 已经抽象了一些通用功能，你可以把它 use 进  \n你的支付方式类里面。\n\n可以参考 `Phwoolcon\\Payment\\Tests\\Helper\\TestPaymentMethod`\n\n每个支付方式至少**应该**实现两个动作：  \n`payRequest` 和 `callback`\n\n你可以给你的支付方式添加任何动作，通过设置 `Processor::run()` Payload \n里面的 `action` 参数来调用。\n\n任何动作都**应该**返回一个 `Phwoolcon\\Payment\\Process\\Result` 对象，该对象  \n要么包含一个订单 `Order`，要么包含一个错误信息。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphwoolcon%2Fpayment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphwoolcon%2Fpayment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphwoolcon%2Fpayment/lists"}