kozin8 / elopage-php
Elopage API php 封装器
Requires
- php: ^5.3 || ^7.0 || ^8.0
- ext-curl: *
- ext-json: *
README
Elopage API php 封装器
注意
注意!
API服务不规范,返回错误格式不同,不依赖于返回的服务器代码等。在这个库中已尝试标准化响应,但并不总是正确。特别是在翻译方面。
我为不稳定的工作表示歉意。
安装
composer require kazin8/elopage
您能做什么?
认证
通过在请求中使用您的秘密API密钥来认证您的账户。您可以在仪表板设置中创建或更新您的API密钥。请保管好您的API和秘密密钥,不要在GitHub等公共场合分享您的API密钥。
在生产环境中,您必须通过HTTPS创建请求,否则调用将失败。沙盒请求可以使用HTTP。
沙盒和支付凭证
您可以使用API的测试模式(用于测试)。
测试支付的凭证在生产环境中无法使用。目前,我们除了实际支付外,没有在生产环境中测试支付的功能。
信用卡
以下信用卡号可用于测试Visa或Mastercard支付。
Sofort Überweisung (Klarna)
以下在线银行和账户凭证可用于测试Sofort Überweisung (Klarna)支付。
SEPA
请使用以下支付信息来测试即时成功和失败的支付。请注意,初始支付需要5天处理。在此期间,支付将处于“挂起”状态。SEPA支付适用于零售商类型账户。
Paypal
请使用以下Paypal凭证来测试预演中的支付。请注意,除非您在生产环境中连接自己的Paypal账户,否则您无法检查Paypal账户的支付状态(通过登录Paypal)。
创建API实例
$api = new ElopageApi($apiKey, $secret, $testMode = false);
- apiKey - 仪表板中的API密钥
- secret - 仪表板中的秘密密钥
- testMode - false|true 使用测试模式
设置错误语言
该库支持两种语言版本 - 英语(en)和德语(de)。
默认选择英语版本。
您可以设置其他语言
$api->setLanguage($api::LANG_DE);
响应对象
所有方法都返回一个通用响应对象。(ResponseDto类的实例)。
如果发生错误,将返回ErrorDto类的对象。
该对象有多个方法可以帮助您处理API。
/* Get the list of products */
$response = $api->get('products');
验证请求的成功
if ($response->isSuccess()) {
// do something;
}
获取响应数据
if ($response->isSuccess()) {
$data = $response->getData();
} else {
$error = $response->getError();
}
错误和异常
错误类有以下方法
API错误列表
该库有其自己的异常,您可以在发生错误时抛出。
if ($response->isSuccess()) {
$data = $response->getData();
} else {
throw new ElopageApiException($response->getError()->getMessage(), $response->getError()->getCode());
}
API方法
有关输入参数和响应结构的更多信息,请参阅文档: Elopage API文档
产品
获取产品
$response = $api->get('products', $id);
获取产品列表
$response = $api->get('products');
创建产品
$payload = [
'name' => 'product name',
'success_url' => 'elopage.com',
'cancel_url' => 'elopage.com',
'error_url' => 'elopage.com',
'webhook_url' => 'elopage.com',
'pricing_plans' => [
[
'form' => 'one_time',
'preferences' => [
'price' => '199.9',
'old_price' => '200',
],
],
],
'authors' => [
[
'id' => 4,
'custom_commission_enabled' => true,
'commission' => 10,
],
],
'success_email' => [
'subject_de' => 'test',
'body_de' => '<p>Hallo %{first_name} %{last_name},</p>\n<p><br></p>\n<p>vielen Dank für die Bestellung.</p>\n<p><br></p>\n<p>Produktname: %{product_name}</p>\n<p>Betrag: %{amount}</p>\n<p>Zahlung: %{recurring_type}</p>\n<p><br></p>\n<p>Bitte jetzt hier klicken:</p>\n<p>%{next_button}</p>\n<p><br></p>\n<p>Schöne Grüße,</p>',
'subject_en' => 'test',
'body_en' => '<p>Hello %{first_name} %{last_name},</p>\n<p><br></p>\n<p>thanks for your order.</p>\n<p><br></p>\n<p>Product name: %{product_name}</p>\n<p>Amount: %{amount}</p>\n<p>Plan: %{recurring_type}</p>\n<p><br></p>\n<p>Now click here:</p>\n<p>%{next_button}</p>\n<p><br></p><p>Best regards,</p>',
],
];
$response = $api->post('products', $payload);
更新产品
$id = 1;
$payload = [
'name' => 'product name',
'success_url' => 'elopage.com',
'cancel_url' => 'elopage.com',
'error_url' => 'elopage.com',
'webhook_url' => 'elopage.com',
'pricing_plans' => [
[
'id' => 1340,
'form' => 'one_time',
'preferences' => [
'price' => '220',
'old_price' => '200.0',
],
],
],
'success_email' => [
'subject_de' => 'test',
'body_de' => '<p>Hallo %{first_name} %{last_name},</p>\n<p><br></p>\n<p>vielen Dank für die Bestellung.</p>\n<p><br></p>\n<p>Produktname: %{product_name}</p>\n<p>Betrag: %{amount}</p>\n<p>Zahlung: %{recurring_type}</p>\n<p><br></p>\n<p>Bitte jetzt hier klicken:</p>\n<p>%{next_button}</p>\n<p><br></p>\n<p>Schöne Grüße,</p>',
'subject_en' => 'test',
'body_en' => '<p>Hello %{first_name} %{last_name},</p>\n<p><br></p>\n<p>thanks for your order.</p>\n<p><br></p>\n<p>Product name: %{product_name}</p>\n<p>Amount: %{amount}</p>\n<p>Plan: %{recurring_type}</p>\n<p><br></p>\n<p>Now click here:</p>\n<p>%{next_button}</p>\n<p><br></p><p>Best regards,</p>',
],
];
$response = $api->put('products', $payload, $id);
出版商
获取出版商列表
$response = $api->get('publishers');
将出版商注册到计划中
$payload = [
'affiliate_program_id' => 1
];
$response = $api->post("publishers/{$id}/enroll", $payload);
从计划中取消出版商注册
$payload = [
'affiliate_program_id' => 1
];
$response = $api->post("publishers/{$id}/unenroll", $payload);
定价计划
获取定价计划
$response = $api->get('pricing_plans', $id);
创建定价计划
$payload = [
'sales_page_id' => 1087,
'pricing_plan' =>
[
'form' => 'split',
'preferences' => [
'p_count' => 2,
'first_amount' => 0.5,
'next_amount' => 2,
],
],
];
$response = $api->post('pricing_plans', $payload);
删除定价计划
$response = $api->delete('pricing_plans', $id);
支付
获取支付信息
$response = $api->get('payments', $id);
退款
获取退款信息
$response = $api->get('payments', $id);
创建退款
$paymentId = 1;
$payload = [];
$response = $api->post("payments/{$paymentId}/refund", $payload);
贡献
当向此仓库贡献时,请先通过issue讨论您希望进行的更改,然后再提交pull request。
作者
弗拉基米尔·瓦西科夫 - kazin8
许可证
本项目采用MIT许可证 - 有关详细信息,请参阅LICENSE文件。