arcansecurity/skeerel-php

此包已被废弃且不再维护。没有建议的替代包。

Skeerel PHP 库

2.5.5 2020-05-08 17:12 UTC

This package is not auto-updated.

Last update: 2024-09-21 14:27:57 UTC


README

Latest Stable Version License

A PHP library for the Skeerel API https://doc.skeerel.com

需求

最低 PHP 版本:5.4.0

安装

通过 composer

composer require arcansecurity/skeerel-php 2.5.5

或在您的 composer.json 文件中

{
  "require": {
    "arcansecurity/skeerel-php": "2.5.5"
  }
}

手动安装

如果您不想使用 Composer,您可以下载最新的发布版。然后,要使用绑定,请包含 init.php 文件。

require_once('/path/to/skeerel-php/init.php');

用法

生成状态令牌

当您向用户展示登录页面时,您必须设置一个会话令牌以避免一些 XSRF 攻击。以下行将为您完成这项工作

\Skeerel\Skeerel::generateSessionStateParameter();

// Eventually, you can set the name of the session
\Skeerel\Skeerel::generateSessionStateParameter("my_custom_session_name");

显示按钮

为了连接或支付,用户必须点击 Skeerel 按钮。

将按钮插入页面非常简单。只需将此代码粘贴到您希望按钮出现的位置

    <script type="text/javascript" src="https://api.skeerel.com/assets/v2/javascript/api.min.js"
        id="skeerel-api-script"
        data-website-id="YOUR_WEBSITE_ID"
        data-state="<?php echo \Skeerel\Util\Session::get(\Skeerel\Skeerel::DEFAULT_COOKIE_NAME); ?>"
        data-redirect-url="The url where the user will be redirected once he has complete"
        data-profile-id="SKEEREL_PROFILE_ID" // to force the payment being done with a particular profile
        data-need-shipping-address="" // in case you need a shipping address
        data-need-billing-address="" // in case you need a billing address
        data-delivery-methods-url="https://site.com/delivery_methods.php?user=__USER__&zip_code=__ZIP_CODE__&city=__CITY__&country=__COUNTRY__" // If you need to ship something to the user
        data-checkout="" // If the session is for the user to pay
        data-payment-test="" // If the payment must be done in test mode
        data-amount="1000" // Amount is in the smallest common currency unit. For instance here 10,00€ 10.00USD, ¥1000
        data-currency="eur" // The currency of the transaction
        data-custom="{'product_id': 3000}" // some custom data (if necessary)></script>

处理配送方式

当用户使用 Skeerel 支付时,您可能需要发货。在这种情况下,只需在您的 data-delivery-methods-url 参数中设置 Skeerel 应调用的 URL 来获取您的配送方式。例如

https://site.com/path/to/delivery/methods_
https://site.com/path/to/delivery/methods?uid=__USER___
https://site.com/path/to/delivery/methods?uid=__USER__&zip_code=__ZIP_CODE&city=__CITY__&country=__COUNTRY__
https://site.com/path/to/delivery/methods?some_var=some_value&zip_code=__ZIP_CODE&city=__CITY__&country=__COUNTRY__

您可以根据需要自定义 URL,因此可以发送准确的运费报价。

注意,__USER__(用户标识符)、__ZIP_CODE____CITY____COUNTRY__(两位字母的国家代码)是通用值,将在调用您的页面之前自动替换。

客人结账 的情况下,__USER__ 值将设置为空字符串。

为了格式化配送方式,我们建议您使用我们的嵌入式方法

// A standard delivery mode
$deliveryMethodStandard = new DeliveryMethod();
$deliveryMethodStandard->setId("standard");
$deliveryMethodStandard->setType(Type::HOME());
$deliveryMethodStandard->setPrimary(true);
$deliveryMethodStandard->setName("Standard shipping");
$deliveryMethodStandard->setDeliveryTextContent("delivery in 3 days");
$deliveryMethodStandard->setPrice(499);



// But also a pick up mode
$deliveryMethodRelay = new DeliveryMethod();
$deliveryMethodRelay->setId("my_relay");
$deliveryMethodRelay->setType(Type::RELAY());
$deliveryMethodRelay->setName("Pick-up & go");
$deliveryMethodRelay->setDeliveryTextContent("Deliver on $dateTwoDays");
$deliveryMethodRelay->setPrice(299);

// Pick up points
$pickUpPoint1 = new PickUpPoint();
$pickUpPoint1->setId("1");
$pickUpPoint1->setName("Pick-up 1");
$pickUpPoint1->setAddress("Address 1");
$pickUpPoint1->setZipCode($zip);
$pickUpPoint1->setCity($city);
$pickUpPoint1->setCountry($country);
$pickUpPoint1->setDeliveryTextContent("tomorrow");
$pickUpPoint1->setDeliveryTextColor(Color::GREEN());
$pickUpPoint1->setPrice(399);
$pickUpPoint1->setPriceTextColor(Color::RED());

$pickUpPoint2 = new PickUpPoint();
$pickUpPoint2->setId("2");
$pickUpPoint2->setPrimary(true);
$pickUpPoint2->setName("Pick-up 2");
$pickUpPoint2->setAddress("address 2");
$pickUpPoint2->setZipCode($zip);
$pickUpPoint2->setCity($city);
$pickUpPoint2->setCountry($country);

$pickUpPoint3 = new PickUpPoint();
$pickUpPoint3->setId("3");
$pickUpPoint3->setName("Pick-up 3");
$pickUpPoint3->setAddress("Address 3");
$pickUpPoint3->setZipCode($zip);
$pickUpPoint3->setCity($city);
$pickUpPoint3->setCountry($country);

$pickUpPointsRelay = new PickUpPoints();
$pickUpPointsRelay->add($pickUpPoint1);
$pickUpPointsRelay->add($pickUpPoint2);
$pickUpPointsRelay->add($pickUpPoint3);

$deliveryMethodRelay->setPickUpPoints($pickUpPointsRelay);



// And why not getting the order directly in the store
$deliveryMethodCollect = new DeliveryMethod();
$deliveryMethodCollect->setId("store_collect");
$deliveryMethodCollect->setType(Type::COLLECT());
$deliveryMethodCollect->setName("Clic & collect");
$deliveryMethodCollect->setDeliveryTextContent("Available in two hours");
$deliveryMethodCollect->setPrice(0);

// Collect points
$collectPoint1 = new PickUpPoint();
$collectPoint1->setId("1");
$collectPoint1->setName("Store 1");
$collectPoint1->setAddress("Address 1");
$collectPoint1->setZipCode($zip);
$collectPoint1->setCity($city);
$collectPoint1->setCountry($country);

$collectPoint2 = new PickUpPoint();
$collectPoint2->setId("2");
$collectPoint2->setName("Store 2");
$collectPoint2->setAddress("Address 2");
$collectPoint2->setZipCode($zip);
$collectPoint2->setCity($city);
$collectPoint2->setCountry($country);

$collectPoint3 = new PickUpPoint();
$collectPoint3->setId("3");
$collectPoint3->setName("Store 3");
$collectPoint3->setAddress("Address 3");
$collectPoint3->setZipCode($zip);
$collectPoint3->setCity($city);
$collectPoint3->setCountry($country);

$pickUpPointsCollect = new PickUpPoints();
$pickUpPointsCollect->add($collectPoint1);
$pickUpPointsCollect->add($collectPoint2);
$pickUpPointsCollect->add($collectPoint3);

$deliveryMethodCollect->setPickUpPoints($pickUpPointsCollect);



// We add everything to the main object
$deliveryMethods = new DeliveryMethods();
$deliveryMethods->add($deliveryMethodStandard);
$deliveryMethods->add($deliveryMethodRelay);
$deliveryMethods->add($deliveryMethodCollect);

// And we show the json
echo $deliveryMethods->toJson();

获取完成时的详细信息

当用户使用 Skeerel 登录或支付时,浏览器将自动将其重定向到您的 data-redirect-url 参数。要检索他的数据,您只需调用以下行

// Verify that the state parameter is the same
if (\Skeerel\Skeerel::verifyAndRemoveSessionStateParameter($_GET['state'])) {
    $skeerel = new \Skeerel\Skeerel('YOUR_WEBSITE_ID', 'YOUR_WEBSITE_SECRET');
    $data = $skeerel->getData($_GET['token']);
}

有关获取用户信息的更多信息,您可以查看 Skeerel/Data 目录下的类。

获取支付详情

$skeerel = new \Skeerel\Skeerel('YOUR_WEBSITE_ID', 'YOUR_WEBSITE_SECRET');
$payment = $skeerel->getPayment("ce365eec-c287-43b6-ad38-25d8d9029fd1");

列出支付

支付按日期降序排列。最后付款显示在第一位

$skeerel = new \Skeerel\Skeerel('YOUR_WEBSITE_ID', 'YOUR_WEBSITE_SECRET');
$payment = $skeerel->listPayments(); // last ten payments
$payment = $skeerel->listPayments(true); // last ten live payments
$payment = $skeerel->listPayments(true, 15, 20); // list twenty payments starting from the fifteenth index

退款支付

$skeerel = new \Skeerel\Skeerel('YOUR_WEBSITE_ID', 'YOUR_WEBSITE_SECRET');
$skeerel->refundPayment("32b2fe1a-d987-487b-9fa1-e10964212e76"); // full refund
$skeerel->refundPayment("32b2fe1a-d987-487b-9fa1-e10964212e76", 100); // partial refund (amount is in the currency's smallest unit. Ex 50€ => 5000)

审查支付

当支付似乎可疑时,Skeerel 持有资金但不扣款。

这样您可以手动审查支付,并且只有在支付是合法的(从而避免争议)时才扣款金额。如果是欺诈性的,您可以简单地拒绝支付。如果七天内没有拒绝支付,支付将自动取消。

以下代码显示了如何扣款或拒绝支付。

$skeerel = new \Skeerel\Skeerel('YOUR_WEBSITE_ID', 'YOUR_WEBSITE_SECRET');
$skeerel->capturePayment("32b2fe1a-d987-487b-9fa1-e10964212e76"); // payment is legit, capture it
$skeerel->rejectPayment("32b2fe1a-d987-487b-9fa1-e10964212e76"); // payment is fraudulent, reject it

获取网站详情

$skeerel = new \Skeerel\Skeerel('YOUR_WEBSITE_ID', 'YOUR_WEBSITE_SECRET');
$skeerel->getWebsiteDetails();

示例应用

如果您想看看这个库的示例,请查看 Skeerel PHP 示例应用 这里

资源

查看 API 文档
访问您的 客户仪表板