prestashop/prestashop-accounts-auth

PrestaShop 账户 composer 库

该包的官方仓库似乎已不存在,因此该包已被冻结。


README

社区服务和 PrestaShop X 模块

要作为社区服务或 PrestaShop X 运行,模块需要三个部分

module ps_accounts

  • 包含所有控制器

library npm

  • 包含所有用于管理的 vuejs 组件

library composer

  • 包装所有对 ps_accounts 的调用
  • 包含所有 Firebase 逻辑

安装

composer require prestashop/prestashop-accounts-auth

使用

每个 PrestaShop X 模块都需要安装 ps_accounts 模块才能进行入门流程。PrestaShop X 模块需要在它们的 install() 方法中安装 ps_accounts。为了简化这一过程,我们为您创建了一个处理方法。

(new PrestaShop\AccountsAuth\Installer\Install())->installPsAccounts()

例如:您需要在模块的主类中的 install() 方法中调用上述方法。

/**
 * Function executed at the install of the module
 *
 * @return bool
 */
public function install()
{
  return (new PrestaShop\AccountsAuth\Installer\Install())->installPsAccounts() &&
    parent::install();
}

在您的 PrestaShop X 或社区服务模块中

  • 在模块的控制器和/或主类中,获取入门表示器并转到 viewsjs 组件 所使用的视图。
$psAccountPresenter = new PrestaShop\AccountsAuth\Presenter\PsAccountsPresenter($this->name);

Media::addJsDef([
    'contextPsAccounts' => $psAccountPresenter->present(),
]);

$psAccountPresenter 的格式为

[
    'psIs17' => bool,
    'psAccountsInstallLink' => null|string,
    'psAccountsEnableLink' => null|string,
    'onboardingLink' => string,
    'user' => [
        'email' => null|string,
        'emailIsValidated' => bool,
        'isSuperAdmin' => bool,
    ],
    'currentShop' =>  [
        'id' => string,
        'name' => string,
        'domain' => string,
        'domainSsl' => string,
        'url' => string,
    ],
    'shops' => [],
    'firebaseRefreshToken' => null|string,
    'superAdminEmail' => string,
    'ssoResendVerificationEmail' => string,
];

账单

此库还提供 PrestaShop 账单功能和助手,以便您的模块可以调用 PrestaShop 账单 API。

注意:要调用账单 API,您需要首先入门商店。

入门后订阅免费计划

入门成功后,您可能需要将您的商家注册到基础账单计划(如果您有多个服务级别,则基础计划可能是免费的)。让它进行。

$billingService = new \PrestaShop\AccountsAuth\Service\PsBillingService();
$shopId = false; // Set this ID to the current shop in multishop context. False otherwise.
$ip = null; // Set this to the browser IP (the call is made from the backoffice by the merchant).
$result = $billingService->subscribeToFreePlan('<your_module>', '<your_basic_plan>', $shopId, $ip);

结果将显示这些 ID

[
    'shopAccountId' => '<The PS Accounts shop ID, set after onboarding>',
    'customerId' => '<The PS Billing customer ID, linked to shop account>',
    'subscriptionId' => '<The subscription ID of the given plan>'
]

或如果出现错误,将抛出 \Exception 异常。

  • 代码 10:'商店账户未知'。商店尚未完全进入 PS 账户流程。
  • 代码 20:'订阅计划名称不匹配'。提供的计划不匹配可用的计划。
  • 代码 50:'账单客户请求失败'。无法执行 API 调用。
  • 代码 51:'账单订阅请求失败'。无法执行 API 调用。
  • 代码 60:'账单客户创建失败'。无法创建账单客户。
  • 代码 65:'账单订阅创建失败'。无法创建账单订阅。

测试

运行 php-cs-fixer

php vendor/bin/php-cs-fixer fix

运行 phpstan for prestashop 1.6.1.0

git@github.com:PrestaShopCorp/prestashop_accounts_auth.git path/to/clone

docker run -tid --rm -v ps-volume:/var/www/html --name temp-ps prestashop/prestashop:1.6.1.0;

docker run --rm --volumes-from temp-ps -v $PWD:/web/module -v path/to/clone:/web/ps_accounts -e _PS_ROOT_DIR_=/var/www/html --workdir=/web/module phpstan/phpstan:0.12 analyse --configuration=/web/module/tests/phpstan/phpstan-PS-1.6.neon

运行 phpstan for prestashop 1.7.0.3

git@github.com:PrestaShopCorp/prestashop_accounts_auth.git path/to/clone

docker run -tid --rm -v ps-volume:/var/www/html --name temp-ps prestashop/prestashop:1.7.0.3;

docker run --rm --volumes-from temp-ps -v $PWD:/web/module -v path/to/clone:/web/ps_accounts -e _PS_ROOT_DIR_=/var/www/html --workdir=/web/module phpstan/phpstan:0.12 analyse --configuration=/web/module/tests/phpstan/phpstan-PS-1.7.neon