cloudstek / mollie-php-api
该软件包已被废弃,不再维护。没有建议的替代软件包。
Mollie API 客户端库 for PHP
2.0.1
2016-11-22 22:37 UTC
Requires
- php: >=5.3
- lib-curl: *
- lib-openssl: *
- nategood/httpful: ^0.2.20
Requires (Dev)
- codeclimate/php-test-reporter: ^0.3.2
- frenck/php-compatibility: ^7.0
- phpunit/phpunit: ^5.4
- squizlabs/php_codesniffer: ^2.7
This package is auto-updated.
Last update: 2022-05-18 16:03:29 UTC
README
简单易用、现代且经过良好测试的 Mollie API 客户端库,适用于 Mollie。
要求
- PHP 5.3 或更高版本
- PHP cURL 扩展(含 SSL)
- PHP xdebug 扩展(可选,用于单元测试)
- Composer
- Mollie.com 上的活动网站配置文件(见: Mollie 文档)
特性
目前支持所有不需要 oauth 认证的 API 函数。这意味着您可以使用此 API 客户端进行除管理组织、配置文件、权限和结算之外的所有操作。
- 支付
- 支付方式
- 发行者
- 退款
- 定期支付
- 客户
- 授权
- 订阅
安装
Mollie PHP API 客户端作为 composer 包提供。安装就像在项目中要求该包一样简单。
composer require cloudstek/mollie-php-api
您还可以手动将包添加到项目的 composer.json 要求中
{ "require": { "cloudstek/mollie-php-api": "^2.0.1" } }
接下来,在项目中要求 composer 自动加载器
<?php require_once("vendor/autoload.php");
用法
以下是一些使用 Mollie PHP API 客户端的常见示例。有关高级用法,请参阅 文档。
初始化 Mollie API 客户端类
<?php // Import the namespace use Mollie\API\Mollie; // Create an API client instance $mollie = new Mollie('test_yourapikeyhere'); // Alternatively.. $mollie = new Mollie(); $mollie->setApiKey('test_yourapikeyhere'); // Now you're ready to use the Mollie API, please read on for more examples.
创建新客户
<?php use Mollie\API\Mollie; // Initialize API client $mollie = new Mollie('test_yourapikeyhere'); // Create customer $customer = $mollie->customer()->create('John Doe', 'john.doe@example.org'); // Alternatively you can also specify a locale and/or metadata. // In the following example we'll create the same customer with some metadata $customer = $mollie->customer()->create( 'John Doe', 'john.doe@example.org', array( 'user_id' => 11, 'group' => 'regular_customers' ) ); // Now save the customer ID to your database for future reference. Pseudo code: $db->save($customer->id);
支付
常规支付
<?php use Mollie\API\Mollie; // Initialize API client $mollie = new Mollie('test_yourapikeyhere'); // Create new payment $payment = $mollie->payment()->create( 10.00, 'Expensive cup of coffee', 'https://example.org/order/101' ); // Redirect user to payment page $payment->gotoPaymentPage();
客户支付
根据 Mollie API 文档,将客户与支付关联可启用一系列 Mollie Checkout 功能,包括
- 客户的支付偏好。
- 允许客户通过单击一次即可使用之前使用的借记卡或信用卡。
- 改进仪表板中的支付洞察。
- 定期支付。
<?php use Mollie\API\Mollie; // Initialize API client $mollie = new Mollie('test_yourapikeyhere'); // Create new payment $payment = $mollie->customer('cst_test')->payment()->create( 10.00, 'Expensive cup of coffee', 'https://example.org/order/101' ); // Redirect user to payment page $payment->gotoPaymentPage(); exit; // Do redirect immediately
定期支付
获取定期支付授权
<?php use Mollie\API\Mollie; // Initialize API client $mollie = new Mollie('test_yourapikeyhere'); // Get customer $customer = $mollie->customer('cst_test')->get(); // Make sure the customer has no valid mandates if(!$customer->mandate()->hasValid()) { // Create mandate by issueing the first recurring payment. // This is usually a small amount like a few cents as it's only used to confirm // the payment details. $customer->mandate()->createFirstRecurring( 0.01, 'Recurring payment mandate confirmation', 'https://example.org/account' ); }
创建定期支付
<?php use Mollie\API\Mollie; // Initialize API client $mollie = new Mollie('test_yourapikeyhere'); // Get customer $customer = $mollie->customer('cst_test')->get(); // Check if customer has a valid mandate for recurring payments if($customer->mandate()->hasValid()) { $customer->payment()->createRecurring(10.00, 'Expensive cup of coffee'); } else { // Customer has no valid mandates, you should get one first. }
变更日志
请参阅 CHANGELOG.md 以获取完整的更改列表。
贡献
请随时通过提交拉取请求和提出问题来对代码进行贡献,以表达您的想法和功能请求。
如果您贡献代码,请确保它包含单元测试,并且能够通过现有的测试,以防止回归问题。