webservco/paypal
最新稳定版本:v1.0.1
Composer 安装命令:
composer require webservco/paypal
包简介
A PHP component/library.
关键字:
README 文档
README
A PayPal REST API implementation.
Implemented functionality: Orders v2.
Resources
Storage
Structure
Both table names and field names can be customized.
Table payment_order
Fields to add to an existing table
- Mandatory:
order_reference: implementation specific, eg.VARCHAR(45) NOT NULL, - Mandatory:
order_total: implementation specific, eg.DECIMAL(10,2) NOT NULL - Optional:
order_currency:CHAR(3) NOT NULL, - Mandatory:
order_payment_statusVARCHAR(45) DEFAULT NULL, - Mandatory:
payment_event_date_timeDATETIME DEFAULT NULL,
New table example
CREATE TABLE payment_order ( order_reference VARCHAR(45) NOT NULL, order_total DECIMAL(10,2) NOT NULL, order_currency CHAR(3) NOT NULL, order_payment_status VARCHAR(45) DEFAULT NULL, payment_event_date_time DATETIME DEFAULT NULL, PRIMARY KEY(order_reference) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
Table payment_access_token
CREATE TABLE payment_access_token ( token VARCHAR(100) NOT NULL, expire_date_time DATETIME NOT NULL, added_date_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(token) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
Configuration
Use environment variables (check example configuration) (app url, default currency, table and fields names);
If not using order level currency, make sure to set the PAYMENT_DEFAULT_CURRENCY options, and leave blank PAYMENT_FIELD_NAME_ORDER_CURRENCY.
If using a very specialized setup and using the configuration is not enough, you can implement \WebServCo\Contract\Storage\Order\OrderPaymentStorageInterface specifically for your project.
Usage
An example is located in the directory public/payment.
Copy the files in your local project and adapt the paths.
Note: If a custom implementation is required, check and adapt the code located in src/example_implementation.
Testing the example implementation
- Create
config/.env.ini; - Fill paypal info
- Start project:
ddev start - Create tables;
- Create a test order:
INSERT INTO `payment_order` (order_reference, order_total, order_currency) VALUES ('Test1', 123.45, 'EUR');
- Open payment page:
https://paypal.ddev.site/payment/pay.php?orderReference=Test1&languageCode=en
Note: languageCode is optional and only used internally in implementing project.
If you set it when initialize the payment, it will arrive as parameter to the PAYMENT_RESULT_LOCATION and the PAYMENT_CANCEL_LOCATION.
TODO
[ ] Find a way to suppress Psalm "UnusedVariable" errors.
Not working (generates "UnusedPsalmSuppress" error):
/** * @psalm-suppress UnusedVariable */
/** @psalm-suppress UnusedVariable */
Reference: Docblock suppression
统计信息
- 总下载量: 45
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-01-31