sveaekonomi / webpay
Svea Ekonomi 支付方式集成库
Requires
- php: >=5.3.0
- ext-curl: *
- ext-soap: *
- sveaekonomi/checkout: ^1.0.0
Requires (Dev)
- phpunit/phpunit: ^8
README
索引
-
- 7.1 WebPayAdmin::queryTaskInfo()
- 7.2 WebPayAdmin::cancelOrder()
- 7.3 WebPayAdmin::queryOrder()
- 7.4 WebPayAdmin::cancelOrderRows()
- 7.5 WebPayAdmin::creditOrderRows()
- 7.6 WebPayAdmin::addOrderRows()
- 7.7 WebPayAdmin::updateOrderRows()
- 7.8 WebPayAdmin::deliverOrderRows()
- 7.9 WebPayAdmin::updateOrder()
- 7.10 WebPayAdmin::creditAmount()
- 7.11 WebPayAdmin::creditOrderRows()
- 7.12 WebPayAdmin::cancelRecurSubscription()
I. 简介
关于 Svea 检查出的一则简短说明
如果您想要一个仅包含检查出的轻量级集成包,可以使用 php-checkout 集成包。
有关如何集成 Svea 检查出更多信息,请参阅第 6.7 WebPay::checkout() 节,如果需要查看更详细的数据结构,请参阅此 文档。
Svea API
WebPay 类包含创建订单和执行支付请求所需的方法。它包含定义订单内容、发送订单请求以及支持方法。
WebPayAdmin 类的方法用于在 Svea 接受订单后管理订单。它包括更新、交付、取消和冲销订单等方法,并可管理所有类型的订单。
包设计理念
通常情况下,使用Svea API的请求从创建一个订单构建器类的实例开始,然后通过流畅的方法调用填充数据。在某个时刻,使用一个方法选择请求将针对哪个服务。这个方法返回一个服务请求类的实例,该类负责构建请求的具体细节,进而返回一个对应的服务响应类的实例以供检查。
WebPay API由WebPay和WebPayAdmin类中的入口方法组成。这些方法在Svea命名空间中实例化构建器类。例如,有一个订单构建器实例,您可以使用方法调用填充订单行和客户识别数据。然后选择支付方式,并返回一个请求类。然后发送请求,并从Svea获取服务响应。一般来说,请求类将验证所有必需的构建器类属性是否存在,如果不存在,将抛出一个异常,指出针对该请求缺少哪些方法。
同步和异步请求
大多数服务请求是同步的,并立即返回响应。对于异步托管服务支付请求,客户将被重定向到所选的卡支付提供商或银行,您将收到一个回调到返回URL,在那里您接收并解析响应。
命名空间
该包使用PHP命名空间,将大多数类分组在Svea命名空间下。入口类WebPay、WebPayAdmin及其相关支持类不包括在Svea命名空间中。底层内部服务和方法包含在Svea子命名空间WebService、HostedService和AdminService中。
流畅API
该包构建为流畅API,因此您可以在使用WebPay和WebPayAdmin入口类时使用方法链。可用的方法应在IDE中显示,包括与其关联的DocBlock,包括有关各种支付方法所需方法的说明。我们建议确保您的IDE代码补全功能已启用,以充分利用此功能。
1. 安装和配置
1.1 需求
此集成包有以下需求
- PHP 5.3或更高版本(推荐5.6+)
- Composer
- 您的Web服务器上需要启用SOAP
1.2 安装
首先,在您的命令行界面中运行以下命令
composer require sveaekonomi/webpay
这样做会将库拉入您的项目,并将其存储在vendor
文件夹中,名称为sveaekonomi
。
当您正在处理将使用库的文件时,需要包含vendor/autoload.php
1.3 配置
为了使用Svea的服务,您需要使用Svea提供的凭据进行身份验证。如果您只是将要使用测试环境,您可以使用集成包中提供的凭据。
对于发票、支付计划和账户信贷支付方式,凭据由一组用户名、密码和客户号(每个国家和服务类型一组)组成。
对于卡和直接银行支付,以及使用结账,凭据由一组(单个)商户ID和密钥词组成。
1.4 使用包中的账户凭据
WebPay和WebPayAdmin入口方法在调用时都需要一个配置对象。获取此类对象的最简单方法是使用ConfigurationService::getDefaultConfig()方法。默认情况下,它返回一个配置对象,其中包含集成包测试套件使用的Svea测试账户凭据。
为了使用您自己的账户凭据,您可以根据所需环境编辑config_test.php或config_prod.php文件(根据所需环境),并使用实际的账户凭据,或者在自己的类中实现ConfigurationProvider接口--您的实现可以从数据库中获取所需的凭据,而不是使用配置文件。
1.5 额外的集成属性配置
您还应该添加有关您的集成平台(例如,Magento、OpenCart或MyAwesomeECommerceSystem等)的信息,平台版本以及提供公司。请参阅ConfigurationProvider getIntegrationPlatform()、getIntegrationVersion()和getIntegrationCompany()方法,或将该信息添加到配置文件中。
配置完成后,集成属性信息将与各种服务请求一起传递给Svea。
有关如何自定义配置文件的示例,请参阅example/config_getaddresses/文件夹。
有关更多信息,请参阅ConfigurationProvider接口和提供的配置文件示例。
2. "Hello World"
以下是一个WebPay API工作流程的示例,即以下发票支付,其中我们希望执行发票订单。假设我们已收集所有必要的订单数据,现在将构建一个包含订购项目(价格、文章编号等信息)和客户信息(姓名、地址等)的订单,选择一种支付方式,并将支付请求发送到Svea。
2.1 一个完整的发票订单
以下是如何使用发票支付方式下订单的完整示例
<?php //Include the library require_once 'vendor/autoload.php'; // Add namespaces use Svea\WebPay\WebPay; use Svea\WebPay\WebPayItem; use Svea\WebPay\Config\ConfigurationService; //Display all errors in case something is wrong error_reporting(E_ALL); ini_set('display_errors', 'On'); // Get configuration object holding the Svea service login credentials $myConfig = ConfigurationService::getDefaultConfig(); // We assume that you've collected the following information about the order in your shop: // The shop cart contains one item "Billy" which cost 700,99 kr excluding vat (25%). // When selecting to pay using the invoice payment method, the customer has also provided their social security number, which is required for invoice orders. // Begin the order creation process by creating an order builder object using the Svea\WebPay\WebPay::createOrder() method: $myOrder = WebPay::createOrder($myConfig); // We then add information to the order object by using the various methods in the Svea\CreateOrderBuilder class. // We begin by adding any additional information required by the payment method, which for an invoice order means: $myOrder->setCountryCode("SE"); $myOrder->setOrderDate(date('c')); // To add the cart contents to the order we first create and specify a new orderRow item using methods from the Svea\WebPay\BuildOrder\RowBuilders\OrderRow class: $boughtItem = WebPayItem::orderRow(); $boughtItem->setDescription("Billy"); $boughtItem->setAmountExVat(700.99); $boughtItem->setVatPercent(25); $boughtItem->setQuantity(1); // Add the order rows to the order: $myOrder->addOrderRow($boughtItem); // Next, we create a customer identity object, for invoice orders Svea will look up the customer address et al based on the social security number $customerInformation = WebPayItem::individualCustomer(); $customerInformation->setNationalIdNumber("194605092222"); // Add the customer to the order: $myOrder->addCustomerDetails($customerInformation); // If a stronger authentication is needed (invoice to SE for example) we need to tell where to redirect after successful/rejected authentication $myOrder->setIdentificationConfirmationUrl('https://mydomain.com/successful-authentication'); $myOrder->setIdentificationRejectionUrl('https://mydomain.com/rejected-authentication'); // We have now completed specifying the order, and wish to send the payment request to Svea. To do so, we first select the invoice payment method: $myInvoiceOrderRequest = $myOrder->useInvoicePayment(); // Then send the request to Svea using the doRequest method, and immediately receive a service response object back $myResponse = $myInvoiceOrderRequest->doRequest(); // If the response attribute accepted is true, the payment succeeded. if($myResponse->accepted == true) { echo "Invoice payment succeeded!"; }; // The response also contains a customerIdentity object containing the invoice address of the customer, which should match the order shipping address. print_r($myResponse->customerIdentity); ?>
上述示例可以在example/firstorder文件夹中找到。
2.2 发生了什么?
上面,我们首先调用API方法WebPay::createOrder(),它返回CreateOrderBuilder类的实例。
然后,使用setCountryCode()、setOrderDate()、addCustomerDetails()和addOrderRow()等类方法将所有必要的订单信息填充到OrderBuilder对象中,以便进行发票订单。
然后,调用useInvoicePayment()方法,返回WebService\InvoicePayment类的实例。然后调用doRequest()方法,它验证提供的订单信息,并将请求发送到Svea,返回WebService\CreateOrderResponse类的实例。
要确定支付请求的结果,我们可以检查响应属性,即检查$myResponse->accepted == true。
2.3 哦,那很酷,但如何直接使用服务呢?
包结构使WebPay和WebPayAdmin入口方法将自己限制在订单域内,并将各种服务请求的详细信息推入包堆栈中,远离集成者的直接视角。因此,所有支付方式和服务都是统一访问的,包主要负责将订单数据整理成所选支付方式或服务请求所需的形式。
这还提供了未来兼容性,因为主要的WebPay和WebPayAdmin入口方法保持稳定,而包如何调用服务的详细信息可能在将来发生变化。
话虽如此,没有额外禁止使用各种服务调用包装类直接访问Svea服务,同时不必担心如何构建各种SOAP调用或格式化XML数据结构等细节。
可以直接实例化服务请求类,确保在执行服务请求之前设置所有相关属性。通常您需要直接在内部请求类中设置属性,因为没有提供设置器方法。
请参阅以下包的WebService、AdminService和HostedService命名空间以获取更多信息。
现在继续阅读,我们将使用WebPay和WebPayAdmin入口点方法通过推荐的WebPay订单构建流程进行操作。
3. 构建订单
在本节中,我们将向您展示创建订单所需的各个步骤。
3.1 订单构建器
首先使用WebPay::createOrder方法创建订单,用于支付方式,或使用WebPay::checkout进行结账方式。传入您的配置并返回OrderBuilder实例。
<?php ... $myOrderBuilder = WebPay::createOrder($myConfig); //or $myOrder = WebPay::checkout($myConfig); ...
3.2 订单行项目
订单行、费用和折扣项目可以添加到订单中。行项目总额构成客户将支付的订单总额。
<?php ... $myOrderRow = WebPayItem::orderRow(); // create the order row object $myOrderRow->setQuantity(1); // required $myOrderRow->setAmountExVat(10.00); // recommended to specify price using AmountExVat & VatPercent $myOrderRow->setVatPercent(25); // recommended to specify price using AmountExVat & VatPercent $myOrder->addOrderRow($myOrderRow); // add order row to the order ... /* the same code expressed in a more compact, fluent style: $myOrder->addOrderRow( WebPayItem::orderRow()->setQuantity(1)->setAmountExVat(10.00)->setVatPercent(25) ); */
有关更多信息,请参阅以下WebPayItem类文档的5.2至5.6节。
3.3 客户身份
使用WebPayItem::individualCustomer()或WebPayItem::companyCustomer()方法创建客户身份对象。使用addCustomerDetails()方法将客户信息添加到订单中。
发票和支付计划订单需要客户身份。对于卡和直接银行订单,这是可选的,但建议使用。
####3.3.1 个人客户的选项
<?php ... $order-> ... addCustomerDetails( WebPayItem::individualCustomer() ->setNationalIdNumber(194605092222) ->setName("Tess", "Testson") ->setStreetAddress("Gatan 23") ->setZipCode(9999) ->setLocality("Stan") ... ) ; ...
有关如何指定客户身份项的更多信息,请参阅以下WebPayItem类文档的5.7和5.8节。
3.4 额外订单属性
使用OrderBuilder方法设置完成订单所需的任何额外属性。
<?php ... $order ... ->setCountryCode("SE") // required, Optional for hosted payments when using implementation of ConfigurationProvider Interface ->setCurrency("SEK") // required for card payment, direct bank & PayPage payments. Ignored for invoice and payment plan. ->setClientOrderNumber("A123456") // Required for card payment, direct payment, Unique String(65). Optional for Invoice and Payment plan String(32). ->setCustomerReference("att: kgm") // Optional for invoice and payment plan String(32), ignored for card & direct bank orders. ->setOrderDate("2012-12-12") // required for invoice and payment plan payments ; ...
3.5 支付方式选择
有两种使用Svea Payments的方式。要么使用结账,要么直接实现支付方式。要集成结账,请参阅第4.6节“Svea Checkout”。
对于支付方式实现,通过使用订单构建器的useXX()方法选择支付方式来完成订单构建过程的指定。例如:$myOrder->useInvoicePayment()
3.5.1 同步支付
发票和支付计划支付方式将对Svea执行同步请求并返回一个响应对象,然后您可以检查它。
3.5.2 异步支付
托管支付方式,如卡、直接银行以及通过PayPage访问的任何支付方式都是异步的。
选择异步支付方式后,通常使用请求类方法获取支付表单对象。然后表单被提交到Svea,客户将被重定向到卡支付服务提供商或银行。客户完成支付后,将向提供的返回URL发送响应,在那里可以处理和检查。
3.5.3 响应URL
对于异步支付方式,您必须指定接收请求响应的位置。使用以下方法
->setReturnUrl()
(必需)当托管支付交易完成时,支付服务将以响应xml消息的形式回答,并将其发送到返回URL。如果用户在例如卡支付页面上取消,这也将是返回URL。
->setCallbackUrl()
(可选)如果托管支付交易完成,但服务无法将响应返回到返回url,Svea将使用回调url(如果指定)作为后备进行多次重试。这种情况可能发生在用户在支付服务将用户重定向回商店之前关闭浏览器,或者交易由于用户输入而超时。在后一种情况下,Svea将在最多30分钟后取消交易,并尝试重定向到回调url。
->setCancelUrl()
(可选,仅限支付页面)在PayPage上显示取消按钮。如果用户取消支付方式选择,Svea将重定向回取消url。除非指定取消url,否则PayPage上不会显示取消按钮。
上述所有url都应该指定完整,包括方案部分。例如,始终使用格式为“http://myshop.com/callback”的url,最大长度为256个字符。(见http://www.w3.org/Addressing/URL/url-spec.txt)。回调url还需要公开可见;不能在例如localhost或仅可通过私有ip地址访问。
接收到的服务响应以XML消息的形式发送,使用SveaResponse响应处理程序来获取响应对象。有关更多详细信息,请参见下文的Svea Response。
3.6 推荐支付方式使用
我在集成中使用发票和/或支付计划支付方式。
最好的方法是使用
->useInvoicePayment()
和->usePaymentPlanPayment()
。这些支付方式是同步的,将为您提供即时响应。
我在集成中使用卡和/或直接银行支付方式。
如果您知道要使用哪种具体的支付方式,最佳方法是直接使用
->usePaymentMethod
转到该特定支付方式,绕过PayPage步骤。您可以使用WebPay::getPaymentMethods()
方法检查您账户上配置的可选支付方式。您还可以使用
->usePayPageCardOnly()
和->usePayPageDirectBankOnly()
与PayPage一起使用。
我在集成中使用所有支付方式,并希望让客户选择使用哪一种。
最有效的方法是使用
->useInvoicePayment()
和->usePaymentPlanPayment()
进行同步支付,并使用->usePaymentMethod()
进行异步请求。首先使用WebPay::getPaymentMethods()
获取您账户上配置的不同支付方式。或者,您可以通过使用
->usePayPageCardOnly()
和->usePayPageDirectBankOnly()
的PayPage来进行异步请求。
我使用多个支付方式,并希望它们在一个地方汇总。
您可以通过PayPage进行,选择在这里显示所有您的支付方式,或者修改以排除或包含一个或多个支付方式。在您可以自定义自己的PayPage的地方使用
->usePayPage()
。这将在客户结账流程中引入一个额外的步骤。请注意,从PayPage使用时,发票和支付计划支付将返回异步响应。
我希望准备一个订单并收到一个可以邮寄给客户、客户然后使用他们的卡完成订单支付的链接。(url有效期为1小时)
创建并构建订单,然后选择使用
->usePaymentMethod()
的卡支付方式,但不要使用->getPaymentForm()
获取发送客户到Webpay的HTTP POST表单,而是使用->getPaymentUrl()
获取发送客户到WebPay的HTTP GET准备好的url。
我希望设置一个使用定期卡片支付的订阅,该订阅每月自动续订,无需进一步的用户交互。
对于定期支付,首先创建一个订单并选择一个卡片支付方法,使用
->usePaymentMethod()
。然后,您在生成的支付请求对象上使用setSubscriptionType()
方法。当最终用户完成交易时,您将在响应中收到一个订阅 ID。
对于后续的定期支付,您再次创建一个订单,并再次使用
->usePaymentMethod()
选择卡片支付方法。然后使用从初始请求中获取的订阅 ID 使用setSubscriptionId()
。然后使用->doRecur()
方法发送支付请求。
参见第 4.3.3 节。
4. 支付方式参考
使用 CreateOrderBuilder 类的 useXX() 方法选择要使用的支付方式,这些方法返回相应的支付请求类实例。
4.1 Svea 发票支付
选择 ->useInvoicePayment() 执行发票支付。
<?php ... $order = WebPay::createOrder($config); $order ->addOrderRow( ... // required, one or more ->addCustomerDetails( ... // required, individualCustomer or companyCustomer ->setCountryCode("SE") // required* Optional for hosted payments when using implementation of ConfigurationProvider Interface ->setOrderDate("2012-12-12") // required ; $request = $order->useInvoicePayment(); // requires the above attributes in the order $response = $request->doRequest(); ...
另一个完整的、可运行的发票订单示例可以在 example/invoiceorder 文件夹中找到。
4.2 Svea 付款计划支付
选择 ->usePaymentPlanPayment() 执行发票支付。
付款计划支付方法仅限于个人客户,不能由法人实体(即公司或组织)使用。
首先使用 WebPay::getPaymentPlanParams() 获取各种活动。然后选择一个活动作为参数传递给 usePaymentPlanPayment() 方法。
<?php ... // fetch all available campaigns from Svea $campaignsRequest = WebPay::getPaymentPlanParams($config); $campaignsRequest->setCountryCode("SE"); $campaignsResponse = $campaignsRequest->doRequest(); // we pick the first available campaign from the response $campaign = $campaignsResponse->campaignCodes[0]->campaignCode; // create the order $order = WebPay::createOrder($config); $order ->addOrderRow( ... ->addCustomerDetails( ... ->setCountryCode("SE") ->setOrderDate("2012-12-12") ; // send the request, using the first available campaign with the payment plan payment method $request = $order->usePaymentPlanPayment($campaign) $response = $request->doRequest(); ...
4.3 卡片支付
选择例如 ->usePaymentMethod(PaymentMethod::SVEACARDPAY) 通过 SveaCardPay 卡片支付提供商执行卡片支付。
4.3.1 ->getPaymentForm()
获取包含请求 XML 数据的 html 表单。表单是 PaymentForm 的实例,同时也包含完整的 html 表单作为字符串以及表单元素数组。
<?php ... $form = $order ->usePaymentMethod(PaymentMethod::SVEACARDPAY) // Card payment, get available providers using WebPay::listPaymentMethods() ->setReturnUrl("http://myurl.se") // Required ->setCancelUrl("http://myurl.se") // Optional ->setCardPageLanguage("sv") // Optional, languageCode As ISO639, eg. "en", default english ->getPaymentForm(); ...
4.3.2 ->getPaymentUrl()
获取包含指向已准备好的支付的链接的 url。已准备好的支付在创建后一小时内有效。要获取支付 url,您需要在订单请求中提供客户 IP 地址和语言。
<?php ... $form = $order ->addCustomerDetails( ... ->setIpAddress() // Required ... ->usePaymentMethod(PaymentMethod::SVEACARDPAY) // Card payment, get available providers using WebPay::listPaymentMethods() ->setReturnUrl("http://myurl.se") // Required ->setCancelUrl("http://myurl.se") // Optional ->setCardPageLanguage("sv") // Required, languageCode As ISO639, eg. "en", default english ->getPaymentUrl(); ...
4.3.3 定期卡片支付
定期卡片支付分为两步设置。首先是一个包括订阅请求的卡片支付,客户输入他们的凭证,然后是任何后续的周期性支付请求,其中使用订阅 ID 代替客户交互。
对于定期支付,首先创建一个订单并选择一个卡片支付方法,使用 ->usePaymentMethod()
。然后,您在生成的支付请求对象上使用 setSubscriptionType()
方法。当最终用户完成交易时,您将在响应中收到一个订阅 ID。
对于后续的定期支付,您再次创建一个订单,并再次使用 ->usePaymentMethod()
选择卡片支付方法。然后使用从初始请求中获取的订阅 ID 使用 setSubscriptionId()
。然后使用 ->doRecur()
方法发送支付请求。
定期卡片订单的示例,包括设置交易和周期性支付,可以在 example/cardorder_recur 文件夹中找到。
4.4 直接银行支付
选择例如 ->usePaymentMethod(PaymentMethod::NORDEA_SE) 使用瑞典银行 Nordea 执行直接银行转账支付。
<?php ... $form = $order ->usePaymentMethod(PaymentMethod::NORDEA_SE) // Direct bank payment, get available banks using WebPay::listPaymentMethods() ->setReturnUrl("http://myurl.se") // Required ->setCancelUrl("http://myurl.se") // Optional ->setCardPageLanguage("sv") // Optional, languageCode As ISO639, eg. "en", default english ->getPaymentForm(); ...
4.5 使用 Svea PayPage
4.5.1 跳过支付方式选择
直接跳转到指定的支付方式,完全跳过 PayPage。通过指定支付方式,您可以消除支付过程中的一个步骤。
您可以使用 WebPay::listPaymentMethods()
获取各种可用的支付方式。
<?php ... $form = $order ->usePaymentMethod(PaymentMethod::SVEACARDPAY) // Use WebPay::listPaymentMethods() to get available payment methods ->setReturnUrl("http://myurl.se") // Required ->setCancelUrl("http://myurl.se") // Optional ->setCardPageLanguage("sv") // Optional, languageCode As ISO639, eg. "en", default english ->getPaymentForm(); ...
4.5.2 选择卡片支付方式
将用户发送到 PayPage 以从可用的卡片中选择(仅限卡片),然后在卡片支付页面上执行卡片支付。
<?php ... $form = $order ->usePayPageCardOnly() ->setPayPageLanguage("sv") // Optional, languageCode As ISO639, eg. "en", default english ->setReturnUrl("http://myurl.se") // Required ->setCallbackUrl("http://myurl.se") // Optional ->setCancelUrl("http://myurl.se") // Optional ->getPaymentForm(); ...
使用 PaymentMethodPayment 的一个完整、可运行的卡片订单示例可以在 example/cardorder 文件夹中找到。
4.5.3 选择直接银行支付方式
将用户发送到 PayPage 以从可用的银行中选择(仅限银行),然后在所选银行执行直接银行支付。
<?php ... $form = $order ->usePayPageDirectBankOnly() ->setPayPageLanguage("sv") // Optional, languageCode As ISO639, eg. "en", default english ->setReturnUrl("http://myurl.se") // Required ->setCancelUrl("http://myurl.se") // Optional ->getPaymentForm() ; ...
4.5.4 指定可用的支付方式
将用户发送到支付页面,以选择可用的支付方式。
<?php ... $form = $order ->usePayPage() ->setPayPageLanguage("sv") // Optional, languageCode As ISO639, eg. "en", default english ->setReturnUrl("http://myurl.se") // Required ->setCancelUrl("http://myurl.se") // Optional ->getPaymentForm() ; ...
您可以使用includePaymentMethods()
、excludePaymentMethods()
、excludeCardPaymentMethods()
和excludeDirectPaymentMethods()
自定义要显示的支付方式。
可用的支付方式在PaymentMethod类和附录中列出。
4.6 Svea Checkout
结算提供了一套完整的解决方案,具有各种支付方式。结算的后端系统是我们的支付计划、账单和账户支付。还包括我们的自有支付网关,支持PCI级别1的卡支付。结算支持B2C和B2B支付,快速客户识别和缓存客户行为。
4.6.1 创建结算订单
创建一个新的结算订单,并返回订单信息和显示IFramed Svea结算所需的Gui。返回完整的订单响应。
结算订单是通过WebPay类创建的。
<?php $orderBuilder = WebPay::checkout($myConfig);
填充订单所需字段的示例。
<?php $orderBuilder->setCountryCode('SE')// customer country, we recommend basing this on the customer billing address ->setCurrency('SEK') ->setClientOrderNumber('123-das-555-32')// required and Unique ->setCheckoutUri('https://:51925/') //required ->setConfirmationUri('https://:51925/checkout/confirm') //required ->setPushUri('https://svea.com/push.aspx?sid=123&svea_order=123') //required ->setTermsUri('https://:51898/terms') //required ->setValidationCallbackUri('https://:51898/validation-callback') // optional ->addIdentityFlag(\Svea\WebPay\Checkout\Model\IdentityFlags::HIDENOTYOU) // optional, hides certain elements in the iframe ->setMerchantData("\"Newsletter\":\"true\"") // optional, sets data on order which is not displayed to end-user but is available in backend ->setLocale('sv-Se'); // required
4.6.1.1 预设值
如果您设置了预设值,则这些值将在加载结算Gui表单时填充。字段可以是“只读”或可编辑的。
<?php $presetPhoneNumber = WebPayItem::presetValue() ->setTypeName(\Svea\WebPay\Checkout\Model\PresetValue::PHONE_NUMBER) ->setValue('some value') ->setIsReadonly(true); $orderBuilder->addPresetValue($presetPhoneNumber);
4.6.1.2 订单行
要能够将Svea订单行Id与您的订单行Id连接起来,您可以使用setTemporaryReference函数。Svea订单行Id将在创建订单响应中返回。通过设置setTemporaryReference,您还可以在响应中获得临时引用。
<?php WebPayItem::fixedDiscount()->setAmountIncVat(10); // this is 10 kr for example, not percent // create and add items to order $firstBoughtItem = WebPayItem::orderRow() ->setAmountIncVat(100.00)// - required ->setVatPercent(25)// - required // - if you want to use discount use ->setQuantity(1) ->setDiscountPercent(20) ->setArticleNumber('123') ->setTemporaryReference('230') // optional. Checkout orders only. Will not be applicable for other order types. ->setMerchantData('gray') // optional. Checkout orders only. Set data which is not displayed to end-users but is available in the backend ->setName('Fork'); $secondBoughtItem = WebPayItem::orderRow() ->setAmountIncVat(10.00) ->setVatPercent(12) ->setQuantity(2) ->setDescription('Korv med bröd') ->setArticleNumber('321') ->setTemporaryReference('231') // optional. Checkout orders only. Will not be applicable for other order types. ->setMerchantData('tasty') // optional. Checkout orders only. Set data which is not displayed to end-users but is available in the backend ->setName('Fork'); $discountItem = WebPayItem::fixedDiscount() ->setName('Promo coupon') ->setVatPercent(10) ->setAmountIncVat(20); $shippingItem = WebPayItem::shippingFee() ->setAmountIncVat(17.60) ->setVatPercent(10) ->setName('incvatShippingFee'); $orderBuilder->addOrderRow($firstBoughtItem); $orderBuilder->addOrderRow($secondBoughtItem); $orderBuilder->addDiscount($discountItem); $orderBuilder->addFee($shippingItem);
4.6.1.3 运行请求
$response = $orderBuilder->createOrder();
4.6.2 获取结算订单
获取有关订单的信息。返回完整的订单响应。
<?php $orderBuilder = WebPay::checkout($config)
现在我们已初始化orderBuilder,可以传递CheckoutOrderId
和可选的国家代码。
<?php $orderBuilder->setCheckoutOrderId(50) ->setCountryCode('SE');
剩下的只是调用getOrder方法来从API获取响应。
<?php $response = $orderBuilder->getOrder();
4.6.3 更新订单
您可以使用更新订单功能来更新已创建的订单。如果消费者在创建订单后更改购物车,请使用此功能。返回完整的订单响应。
<?php $orderBuilder = WebPay::checkout($myConfig); $orderBuilder->setCheckoutOrderId(5) ->setCountryCode('SE'); // create and add items to order $firstBoughtItem = WebPayItem::orderRow() ->setAmountExVat(10.99) ->setVatPercent(25) ->setQuantity(1) ->setDescription("Billy") ->setArticleNumber("123456789A") ->setTemporaryReference('230') // optional. Checkout orders only. Will not be applicable for other order types. ->setMerchantData('hello') // optional. Checkout orders only. Set data which is not displayed to end-users but is available in the backend ->setName('Fork'); $secondBoughtItem = WebPayItem::orderRow() ->setAmountIncVat(5.00) ->setVatPercent(12) ->setQuantity(2) ->setDescription("Korv med bröd") ->setArticleNumber("123456789B") ->setTemporaryReference('231') // optional. Checkout orders only. Will not be applicable for other order types. ->setMerchantData('tasty') // optional. Checkout orders only. Set data which is not displayed to end-users but is available in the backend ->setName('Fork'); $orderBuilder->addOrderRow($firstBoughtItem); $orderBuilder->addOrderRow($secondBoughtItem);
4.6.4 响应
结算方法将返回一个包含响应数据的数组。响应包含有关购物车、商家设置、客户和结算Gui的信息。
有关数据结构的更多详细信息,请参阅连接库的第7节。
示例响应
Array
(
[MerchantSettings] => Array
(
[TermsUri] => https://:51898/terms
[CheckoutUri] => https://:51925/
[ConfirmationUri] => https://:51925/checkout/confirm
[PushUri] => https://svea.com/push.aspx?sid=123&svea_order=123
)
[Cart] => Array
(
[Items] => Array
(
[0] => Array
(
[ArticleNumber] => 123456789
[Name] => Dator
[Quantity] => 200
[UnitPrice] => 12300
[DiscountPercent] => 1000
[VatPercent] => 2500
[Unit] =>
[TemporaryReference] => "230"
)
[1] => Array
(
[ArticleNumber] => SHIPPING
[Name] => Shipping Fee Updated
[Quantity] => 100
[UnitPrice] => 4900
[DiscountPercent] => 0
[VatPercent] => 2500
[Unit] =>
[TemporaryReference] => "231"
)
)
)
[Customer] =>
[ShippingAddress] =>
[BillingAddress] =>
[Gui] => Array
(
[Layout] => desktop
[Snippet] =>
)
[Locale] => sv-SE
[Currency] =>
[CountryCode] =>
[PresetValues] =>
[OrderId] => 9
[Status] => Created
[PaymentType] => NULL
)
结算Gui包含代码片段和布局。代码片段包含您在页面上实现Html和JavaScript的地方的Html和JavaScript,用于显示IFramed结算。布局是一个字符串,定义了客户屏幕的朝向。
echo $response['Gui']['Snippet']
4.6.6 回调
回调在订单流程期间多次发送,回调作为POST发送到pushUri,其中包含结算订单id。例如:https://:63473/shop/orderCallback/{checkout.order.uri}
当您的服务器收到回调时,它是一个通知,表明订单中发生了变化。请发出GetOrder请求以获取最新的订单数据。
4.6.7 获取可用的部分付款活动
GetAvailablePartPaymentCampaigns可用于获取可以存储并用于计算如果客户想以特定活动购买产品,该产品将花费多少的活动。
示例请求
<?php $orderBuilder = WebPay::checkout($myConfig); $presetValueIsCompany = \Svea\WebPay\WebPayItem::presetValue() ->setTypeName(\Svea\WebPay\Checkout\Model\PresetValue::IS_COMPANY) ->setValue(false) ->setIsReadonly(true); $orderBuilder->setCountryCode('SE') ->addPresetValue($presetValueIsCompany); $response = $orderBuilder->getAvailablePartPaymentCampaigns();
示例响应
<?php Array ( [0] => Array ( [CampaignCode] => 213060 [ContractLengthInMonths] => 3 [Description] => Köp nu betala om 3 månader (räntefritt) [FromAmount] => 1000 [InitialFee] => 100 [InterestRatePercent] => 0 [MonthlyAnnuityFactor] => 1 [NotificationFee] => 29 [NumberOfInterestFreeMonths] => 3 [NumberOfPaymentFreeMonths] => 3 [PaymentPlanType] => 2 [ToAmount] => 50000 ) [1] => Array ( [CampaignCode] => 223065 [ContractLengthInMonths] => 3 [Description] => Black Friday - Cyber Monday [FromAmount] => 120 [InitialFee] => 0 [InterestRatePercent] => 0 [MonthlyAnnuityFactor] => 1 [NotificationFee] => 0 [NumberOfInterestFreeMonths] => 3 [NumberOfPaymentFreeMonths] => 3 [PaymentPlanType] => 2 [ToAmount] => 30000 ) [2] => Array ( [CampaignCode] => 310012 [ContractLengthInMonths] => 12 [Description] => Dela upp betalningen på 12 månader (räntefritt) [FromAmount] => 1000 [InitialFee] => 295 [InterestRatePercent] => 0 [MonthlyAnnuityFactor] => 0.083333333333333 [NotificationFee] => 35 [NumberOfInterestFreeMonths] => 12 [NumberOfPaymentFreeMonths] => 0 [PaymentPlanType] => 1 [ToAmount] => 30000 ) [3] => Array ( [CampaignCode] => 410012 [ContractLengthInMonths] => 12 [Description] => Dela upp betalningen på 12 månader [FromAmount] => 100 [InitialFee] => 0 [InterestRatePercent] => 19.9 [MonthlyAnnuityFactor] => 0.092586652785396 [NotificationFee] => 29 [NumberOfInterestFreeMonths] => 0 [NumberOfPaymentFreeMonths] => 0 [PaymentPlanType] => 0 [ToAmount] => 30000 ) )
有关活动的信息,请参阅活动代码信息
4.7 账户信用
选择 -> useAccountCredit() 以执行账户信用支付。
<?php ... $order = WebPay::createOrder($config); $order ->addOrderRow( ... // required, one or more ->addCustomerDetails( ... // required, individualCustomer or companyCustomer ->setCountryCode("SE") // required* Optional for hosted payments when using implementation of ConfigurationProvider Interface ->setCurrency("SEK") // required ->setOrderDate("2012-12-12") // required ; $request = $order->useAccountCredit("111111"); // required campaign code, see example for getting campaigns $response = $request->doRequest(); ...
完整的发票订单示例可以在example/accountcredit文件夹中找到。
4.8 Swish支付
获取包含请求 XML 数据的 html 表单。表单是 PaymentForm 的实例,同时也包含完整的 html 表单作为字符串以及表单元素数组。
如果您正在测试阶段中的Swish支付,您可以设置任何有效号码,支付将自动成功。
<?php ... $config = ConfigurationService::getDefaultConfig(); $form = WebPay::createOrder($config) ->addOrderRow(/*add any orderrow*/) ->setCountryCode("SE") //Required, must be set to "SE" for Swish Payments ->setClientOrderNumber("33") //Required ->setCurrency("SEK") //Required, must be set to "SEK" for Swish Payments ->setPayerAlias("46701234567") //Required, set consumers mobile number ->usePaymentMethod(PaymentMethod::SWISH) //Set payment method to SWISH ->setReturnUrl("http://myurl.se") //Required, this is where the user will be redirected after a successful payment ->setCallbackUrl("http://myurl.se/callback") //Optional, however VERY recommended as redirects from Swish to returnUrl might fail ->getPaymentForm(); ...
4.9 示例
4.9.1 Svea结账订单
完整的结账示例订单可以在example/checkout文件夹中找到。
4.9.2 Svea发票订单
同步(发票)订单的示例可以在example/invoiceorder文件夹中找到。
4.9.3 卡订单
异步卡订单的示例可以在example/cardorder文件夹中找到。
4.9.4 定期卡订单
定期卡订单的示例,包括设置交易和定期支付,可以在example/cardorder_recur文件夹中找到。
4.9.5 Svea账户信用
定期卡订单的示例,包括设置交易和定期支付,可以在[example/accoutncredit(example/accoutncredit)文件夹中找到。
4.9.6 Swish
异步Swish支付的示例可以在example/swishorder文件夹中找到。 返回顶部
5. WebPayItem参考
WebPayItem类提供了访问订单组成的不同行项以及客户身份信息项的入口方法。
订单必须包含一个或多个订单行。您可以将发票费、运费和折扣添加到订单中。
请注意,虽然可以添加多个费用和折扣行,但在发送给Svea之前,包将根据类型对行进行分组。
1. all order rows, in the order they were added using addOrderRow()
2. any shipping fee rows, in the order they were added using addShippingFee()
3. any invoice fee rows, in the order they were added using addShippingFee()
4. any fixed discount rows, in the order they were added using addFixedDiscount()
5. any relative discount rows, in the order they were added using addRelativeDiscount()
此外,对于相对折扣或仅使用setAmountIncVat()或仅使用setAmountExVat()指定的固定折扣,如果订单包含多个不同的税率,则可能添加多个折扣行。不建议在订单中指定多个相对折扣行,或指定多个仅使用setAmountIncVat()或仅使用setAmountExVat()指定的固定折扣。
5.1 指定项目价格
为了指定项目价格和税率,请精确使用以下两种方法之一:setAmountIncVat()
、setVatPercent()
和setAmountExVat()
。
指定项目价格的最佳方式是使用setAmountIncVat()和setVatPercent()方法。这将确保订单总金额和增值税总额与订单项中指定的金额和增值税精确匹配。
当使用setAmountExVat()和setVatPercent()时,服务将具有较低精度,并且可能会累积舍入误差,导致订单总额与行项中指定的金额和增值税总额不同。不建议使用setAmountExVat()方法指定价格。
当使用setAmountIncVat()与setAmountExVat()来指定商品价格时,该软件包会将价格转换为含税金额和税率,以保持最大精度。
注意:当使用WebPayAdmin函数与订单行时,您只能使用WebPayItem::orderRow,并指定价格作为不含税金额和税率。
5.2 WebPayItem::orderRow()
WebPayItem::orderRow()入口方法用于指定订单项,如产品和服务。订单中至少需要有一个订单行。
使用以下两种方法中的精确两种来指定商品价格和税率:setAmountExVat()、setAmountIncVat()和setVatPercent()。我们建议使用setAmountExVat()和setVatPercentage()。
如果使用setAmountIncVat(),请注意,在订购大量商品时,这可能会引入累积舍入误差,因为软件包基于不含税的总订单金额。
<?php ... $orderrow = WebPayItem::orderRow() ->setAmountExVat(100.00) // optional, Float, recommended, use precisely two of the price specification methods ->setVatPercent(25) // optional, Integer, recommended, use precisely two of the price specification methods ->setAmountIncVat(125.00) // optional, Float, use precisely two of the price specification methods ->setQuantity(2) // required ->setUnit("pcs") // optional, String(3) for invoice and payment plan, String(64) for card and direct bank ->setName('name') // optional, invoice & payment plan orders will merge "name" with "description", String(256) for card and direct ->setDescription("description") // optional, String(40) for invoice & payment plan orders will merge "name" with "description" , String(512) for card and direct ->setArticleNumber("1") // optional, String(10) for invoice and payment plan, String (256) for card and direct ->setDiscountPercent(0) // optional ; ...
5.3 WebPayItem::shippingFee()
WebPayItem::shippingFee()入口方法用于指定订单运费行。订单中不需要有运费行。
使用以下两种方法中的精确两种来指定商品价格和税率:setAmountExVat()、setAmountIncVat()和setVatPercent()。我们建议使用setAmountExVat()和setVatPercentage()。
<?php ... $shippingFee = WebPayItem::shippingFee() ->setAmountExVat(100.00) // optional, Float, recommended, use precisely two of the price specification methods ->setVatPercent(25) // optional, Integer, recommended, use precisely two of the price specification methods ->setAmountIncVat(125.00) // optional, Float, use precisely two of the price specification methods ->setUnit("pcs") // optional, String(3) for invoice and payment plan, String(64) for card and direct bank ->setName('name') // optional, invoice & payment plan orders will merge "name" with "description", String(256) for card and direct ->setDescription("description") // optional, String(40) for invoice & payment plan orders will merge "name" with "description" , String(512) for card and direct ->setShippingId('33') // optional ->setDiscountPercent(0) ; // optional ...
5.4 WebPayItem::invoiceFee()
WebPayItem::invoiceFee()入口方法用于指定与支付方式相关的费用(即发票费用)。订单中不需要有发票费用行。
使用以下两种方法中的精确两种来指定商品价格和税率:setAmountExVat()、setAmountIncVat()和setVatPercent()。我们建议使用setAmountExVat()和setVatPercentage()。
<?php ... $invoiceFee = WebPayItem::invoiceFee() ->setAmountExVat(100.00) // optional, Float, recommended, use precisely two of the price specification methods ->setVatPercent(25) // optional, Integer, recommended, use precisely two of the price specification methods ->setAmountIncVat(125.00) // optional, Float, use precisely two of the price specification methods ->setUnit("pcs") // optional, String(3) ->setName('name') // optional, will merge "name" with "description" ->setDescription("description") // optional, String(40) will merge "name" with "description" ->setDiscountPercent(0) ; // optional ...
5.5 WebPayItem::fixedDiscount()
当折扣或优惠券表示为固定折扣金额时,请使用WebPayItem::fixedDiscount()。
如果没有给出税率,我们将根据订单中的订单行税率计算折扣分配。这将确保正确应用折扣税率。
如果订单中有多个税率,折扣将按比例分配给订单行税率。例如,包括结果折扣行,请参阅测试套件文件UnitTest/InvoicePaymentTest.php。
否则,至少需要使用以下函数中的两个:setAmountExVat()、setAmountIncVat()和setVatPercent()。如果指定了这三个属性中的两个,我们将尊重指示的金额和给出的折扣税率。
<?php ... $fixedDiscount = WebPayItem::fixedDiscount() ->setAmountIncVat(100.00) // optional, Float, use precisely two of the price specification methods ->setAmountExVat(1.0) // optional, Float, recommended, use precisely two of the price specification methods ->setVatPercent(25) // optional, Integer, recommended, use precisely two of the price specification methods ->setDiscountId("1") // optional ->setUnit("st") // optional ->setName("Fixed") // optional, invoice & payment plan orders will merge "name" with "description", String(256) for card and direct ->setDescription("FixedDiscount"); // optional, String(40) for invoice & payment plan orders will merge "name" with "description" , String(512) for card and direct ...
5.6 WebPayItem::relativeDiscount()
当折扣或优惠券表示为产品总额的百分比时,请使用WebPayItem::relativeDiscount()。
折扣将基于使用addOrderRow()指定的所有订单行的总金额计算,不适用于发票或运费。
如果订单中有多个税率,折扣将按比例分配给订单行税率。例如,包括结果折扣行,请参阅测试套件文件UnitTest/InvoicePaymentTest.php。
使用RelativeDiscount方法指定折扣
<?php ... $relativeDiscount = WebPayItem::relativeDiscount() ->setDiscountPercent(10.0) // required ->setDiscountId("1") // optional ->setUnit("st.") // optional ->setName("DiscountName") // optional, invoice & payment plan orders will merge "name" with "description", String(256) for card and direct ->setDescription("DiscountDesc.") // optional, String(40) for invoice & payment plan orders will merge "name" with "description" , String(512) for card and direct ; ...
5.7 WebPayItem::individualCustomer()
使用WebPayItem::individualCustomer()向订单添加个人客户信息。
5.7.1 在指定订单时使用IndividualCustomer
请注意,“必需”以下仅当使用发票或付款计划支付方式时为必需,并且必需的属性在不同国家之间有所不同。
(对于卡和直接银行订单,向订单添加客户信息是可选的,除非您使用getPaymentUrl()设置准备付款。)
<?php ... $individual = WebPayItem::individualCustomer() ->setNationalIdNumber() // Numeric // invoice, payment plan: required for customers in SE, NO, DK, FI ->setName() // String // invoice, payment plan: required, use (firstName, lastName) for customers in NL and DE ->setBirthDate() // Numeric // invoice, payment plan: required for individual customers in NL and DE, use date format YYYY-MM-DD ->setInitials() // String // invoice, payment plan: required for individual customers in NL ->setCoAddress() // String // invoice, payment plan: optional ->setStreetAddress() // String // invoice, payment plan: required, use (street, houseNumber) in NL and DE ->setZipCode() // String // invoice, payment plan: required in NL and DE ->setLocality() // String // invoice, payment plan: required in NL and DE ->setPhoneNumber() // String // invoice, payment plan: optional but desirable ->setEmail() // String // invoice, payment plan: optional but desirable ->setIpAddress() // String // invoice, payment plan: optional but desirable; card: required for getPaymentUrl() orders only ->setPublicKey() // String // invoice, payment plan: optional; identifier for selecting a specific pre-approved address ; ...
5.8 WebPayItem::companyCustomer()
使用WebPayItem::companyCustomer()向订单添加个人客户信息。
请注意,“必需”以下仅当使用发票或付款计划支付方式时为必需,并且必需的属性在不同国家之间有所不同。
(对于卡和直接银行订单,向订单添加客户信息是可选的,除非您使用getPaymentUrl()设置准备付款。)
<?php ... $companyCustomer = WebPayItem::companyCustomer() ->setNationalIdNumber() // Numeric // invoice: required for customers in SE, NO, DK, FI ->setCompanyName() // String // invoice: required (companyName) for company customers in NL and DE ->setVatNumber() // Numeric // invoice: required for company customers in NL and DE ->setCoAddress() // String // invoice: optional ->setStreetAddress() // String // invoice: required, use (street, houseNumber) in NL and DE ->setZipCode() // String // invoice: required in NL and DE ->setLocality() // String // invoice: required in NL and DE ->setPhoneNumber() // String // invoice: optional but desirable ->setEmail() // String // invoice: optional but desirable ->setIpAddress() // String // invoice: optional but desirable; card: required for getPaymentUrl() orders only ->setAddressSelector() // String // invoice: optional but recommended; received from WebPay::getAddresses() request response ->setPublicKey() // String // invoice, payment plan: optional; identifier for selecting a specific pre-approved address ; ...
5.9 WebPayItem::numberedOrderRow()
这是订单行类的扩展,用于WebPayAdmin::queryOrder()响应和管理单个订单行的方法。
<?php ... $myNumberedOrderRow = WebPayItem::numberedOrderRow() //inherited from OrderRow ->setAmountExVat(100.00) // recommended to specify price using AmountExVat & VatPercent ->setVatPercent(25) // recommended to specify price using AmountExVat & VatPercent ->setAmountIncVat(125.00) // optional, need to use two out of three of the price specification methods ->setQuantity(2) // required ->setUnit("st") // optional ->setName('Prod') // optional ->setDescription("Specification") // optional ->setArticleNumber("1") // optional ->setDiscountPercent(0) // optional //numberedOrderRow ->setCreditInvoiceId($creditInvoiceIdAsNumeric) //optional ->setInvoiceId($invoiceIdAsNumeric) //optional ->setRowNumber($rowNumberAsNumeric) //required for updateOrderRow ->setStatus(NumberedOrderRow::ORDERROWSTATUS_DELIVERED) //optional, one of _DELIVERED, _NOTDELIVERED, _CANCELLED ; ...
6. WebPay 入口方法参考
WebPay 类的方法包含创建订单和执行支付请求所需的函数,使用 Svea 支付方式。它包含用于定义订单内容、发送订单请求以及执行此操作所需的各种支持方法。
- 6.1 WebPay::createOrder()
- 6.2 WebPay::deliverOrder()
- 6.3 WebPay::getAddresses()
- 6.4 WebPay::getPaymentPlanParams()
- 6.5 WebPay::paymentPlanPricePerMonth()
- 6.6 WebPay::listPaymentMethods()
- 6.7 WebPay::checkout()
6.1 WebPay::createOrder()
使用 WebPay::createOrder() 通过发票、分期付款、卡或直接银行支付方式创建订单。
有关使用 CreateOrderBuilder 类指定订单构建器内容、选择要使用的支付方法以及向 Svea 发送请求后解析响应的更多信息,请参阅。
有关使用 CreateOrderBuilder 类指定订单构建器内容、选择要使用的支付方法以及向 Svea 发送请求后解析响应的更多信息,请参阅。
发票和分期付款订单将在 doRequest() 上执行同步支付,并立即返回响应对象。
卡、直接银行和其他通过 PayPage 访问的托管方法异步。它们提供包含格式化消息的 html 表单,以发送给 Svea。Svea 将将请求响应发送到指定的返回 URL,您可以使用 SveaResponse 类解析响应。
<?php ... $order = WebPay::createOrder($config) ->addOrderRow($orderrow) // required, see WebPayItem::orderRow ->addFee($shippingfee) // optional, see WebPayItem for invoice, shipping fee ->addDiscount($discount) // optional, see WebPayItem for fixed, relative discount ->addCustomerDetails($customer) // required for invoice and payment plan payments, see WebPayItem for individual, company id. ->setCountryCode("SE") // required* Optional for hosted payments when using implementation of ConfigurationProvider Interface ->setOrderDate(date('c')) // required for invoice and payment plan payments ->setCurrency("SEK") // required for card payment, direct bank & PayPage payments. Ignored for invoice and payment plan. ->setClientOrderNumber("A123456") // Required for card payment, direct payment, Unique String(65). Optional for Invoice and Payment plan String(32). ->setCustomerReference("att: kgm") // Optional for invoice and payment plan String(32), ignored for card & direct bank orders. ->setPeppolId("1234:abcd1234") // Optional for invoices where customer type is company, if set the invoice will be sent via PEPPOL ; ...
6.2 WebPay::deliverOrder()
当您向客户交付订单时,请使用 WebPay::deliverOrder 入口。支持发票、分期付款和卡订单。(不支持直接银行订单。)
通常,在已将订购商品发送给客户或已交付给客户后,应向 Svea 发送交付订单请求。
对于发票和部分付款订单,交付订单请求将触发 Svea 向客户发送发票。(这假定您的账户已开启发票自动批准,如果有疑问,请联系 Svea。)
对于卡订单,交付订单请求确认卡交易,这反过来允许 Svea 在夜间批量处理交易。(如果您的账户已关闭自动确认,则需要交付卡订单,如果有疑问,请联系 Svea。)
要全额交付发票、部分付款或卡订单,您不需要指定订单行。要部分交付订单,建议使用 WebPayAdmin::deliverOrderRows()。
有关使用 deliverOrder 部分交付和/或冲销订单的更多信息,请参阅下面的 6.2.3。
使用 WebPay::deliverOrder 入口获取订单构建器实例,然后使用 DeliverOrderBuilder 方法提供更多有关交易的信息。
<?php ... $request = WebPay::deliverOrder($config) ->setOrderId() // invoice, payment plan and accountCredit only - required ->setTransactionId() // card only, optional, alias for setOrderId ->setCountryCode() // required ->setInvoiceDistributionType() // invoice only and accountCredit, required ->setNumberOfCreditDays() // invoice only, optional ->setCaptureDate() // card only, optional ->addOrderRow() // deprecated, optional -- use WebPayAdmin::deliverOrderRows instead ->setCreditInvoice() // deprecated, optional -- use WebPayAdmin::creditOrderRows instead ; // then select the corresponding request class and send request $response = $request->deliverInvoiceOrder()->doRequest(); // returns DeliverOrdersResponse (no rows) or DeliverOrderResult (with rows) $response = $request->deliverPaymentPlanOrder()->doRequest(); // returns DeliverOrdersResponse (no rows) or DeliverOrderResult (with rows) $response = $request->deliverCardOrder()->doRequest(); // returns ConfirmTransactionResponse $response = $request->deliverAccountCreditOrder()->doRequest(); // returns DeliverOrderResponse ...
6.2.1 使用方法
DeliverOrderBuilder 收集和准备订单数据以用于向 Svea 发送交付订单请求。
使用 setOrderId() 指定 Svea 订单 ID,这是原始创建订单请求响应中返回的订单 ID。对于卡订单,您可以可选地使用 setTransactionId()。
使用 setCountryCode() 指定与原始创建订单请求匹配的国家/地区代码。
使用 setInvoiceDistributionType() 与 DistributionType 匹配您的账户配置以发送发票的方式。(如果有疑问,请联系 Svea。)
使用 setNumberOfCreditDays() 指定发票的信用天数。
(已弃用--要部分交付发票订单,您可以使用 addOrderRows() 方法指定要交付的订单行。请使用 WebPayAdmin::deliverOrderRows 入口代替。)
(已弃用--要签发冲销发票,您可以使用 setCreditInvoice() 和 addOrderRows() 指定要交付的信用订单行。请使用 WebPayAdmin::creditOrderRow 入口代替。)
要全额交付发票、部分付款或卡订单,请使用 WebPay::deliverOrder 入口而不指定订单行。
在指定 orderRows 时,WebPay::deliverOrder 的使用方式类似于 WebPay::createOrder,并使用了相同的订单项信息。添加您希望交付的订单行并发送请求,指定的行将自动与创建订单时发送的行匹配。
我们建议将 createOrder 订单行对象存储起来,以确保 deliverOrder 订单行匹配。如果一个在 createOrder 请求中存在的订单行在 deliverOrder 请求中不存在,订单将部分履行,而遗漏的商品将由 Svea 拒绝开具发票。您不能部分履行支付计划订单,所有未取消的订单行都将履行。
6.2.2 示例
以下是一个如何完整履行发票订单的最小示例
<?php require_once 'vendor/autoload.php'; // Add namespaces use Svea\WebPay\WebPay; use Svea\WebPay\Config\ConfigurationService; use Svea\WebPay\Constant\DistributionType; //Display all errors in case something is wrong error_reporting(E_ALL); ini_set('display_errors', 'On'); // Get configuration object holding the Svea service login credentials $myConfig = ConfigurationService::getDefaultConfig(); // We assume that you've previously run the firstorder.php file and successfully made a createOrder request to Svea using the invoice payment method. $mySveaOrderId = "123456"; // Begin the order creation process by creating an order builder object using the WebPay::createOrder() method: $myOrder = WebPay::deliverOrder($myConfig); // We then add information to the order object by using the various methods in the Svea\DeliverOrderBuilder class. // We begin by adding any additional information required by the payment method, which for an invoice order means: $myOrder->setCountryCode("SE"); $myOrder->setOrderId($mySveaOrderId); $myOrder->setInvoiceDistributionType(DistributionType::POST); // We have now completed specifying the order, and wish to send the payment request to Svea. To do so, we first select the invoice payment method: $myDeliverOrderRequest = $myOrder->deliverInvoiceOrder(); // Then send the request to Svea using the doRequest method, and immediately receive the service response object $myResponse = $myDeliverOrderRequest->doRequest(); ?>
上述示例可以在 example/firstdeliver 文件夹中找到。
6.2.3 使用 WebPay::deliverOrder 与订单行
可以通过使用 DeliverOrderBuilder 的 addOrderRow() 方法指定订单行来使用 WebPay::deliverOrder 部分履行、修改或冲销订单。我们建议使用 WebPayAdmin::deliverOrderRows 部分履行订单,以及 WebPayAdmin::creditOrderRows 冲销订单。
6.2.3.1 使用 WebPay::deliverOrder 部分履行
当使用 WebPay::deliverOrder 部分履行订单时,必须注意要履行的订单行必须与原始 WebPay::createOrder 请求中使用的订单行规范精确匹配。除非 deliverOrder 请求中的所有订单行与原始 createOrder 请求中的行完全匹配,否则原始订单中不匹配的订单行将被取消。另请参阅 6.2.3.2 以下内容。
另一方面,如果所有 deliver 订单行都与原始订单行匹配,则原始订单行将与 deliver 订单行匹配并开具发票,发票 ID 将在 DeliverOrderResponse 中返回。其余原始订单行将保持未履行状态,可以在后续的 deliverOrder 请求中履行。
Example:
1. cResponse = WebPay::createOrder()->addOrderRows(A)->addOrderRows(B)->addOrderRows(C)->...->doRequest();
2. dResponse = WebPay::deliverOrder()->addOrderRows(A)->...->doRequest(); // A matches A
Will result in the order having status
A: delivered // found on invoice # dResponse->getInvoiceId()
B: undelivered // may be delivered later
C: undelivered // may be delivered later
6.2.3.2 使用 WebPay::deliverOrder 修改订单
如果您希望向现有订单添加订单行,任何尚未履行的原始订单行将被取消,以便在原始订单总金额内为添加的订单行腾出空间(您可以通过添加与原始订单行完全匹配的订单行在同一个请求中履行订单行)。
确切的行为是,如果 deliver 订单请求中有不匹配任何未履行的原始订单行的订单行,则所有不匹配和未履行的原始订单行将被取消,不匹配的 deliver 订单行将被添加到原始订单中作为新的履行订单行,前提是所有现有履行的行和新增的订单行的总和不超过原始订单行总金额。这意味着不匹配(即添加)的 deliver 订单行的总和不能超过取消的原始订单行的总和。
当履行的订单行金额等于原始订单总金额时,订单将被关闭,防止进一步修改。已履行的订单行只能冲销,另请参阅 6.2.3.3 以下内容。
Example (cont. from 6.2.3.1):
3. dResponse2 = WebPay::deliverOrder()->addOrderRows(D)->...->doRequest(); // D does not match any rows
Will result in the order having status
A: delivered // found on invoice1; dResponse->getInvoiceId()
B: cancelled
C: cancelled
D: delivered // found on invoice2; dResponse2->getInvoiceId()
6.2.3.3 使用 WebPay::deliverOrder 冲销(部分)履行的订单
要冲销订单,请在履行订单时使用 setCreditInvoice(invoiceId) 方法。向 deliver 订单请求添加一个金额为要冲销的金额的订单行。将向客户开具一个带有指定订单行的冲销发票。
在冲销已履行的订单时,实际上是在冲销发票。这意味着如果您部分履行了订单,然后需要冲销整个订单,您将需要发出多个冲销请求,因为冲销发票金额不能超过单个发票总金额。
收到的发票 ID 将指向新的冲销发票本身,原始发票将由 Svea 冲销指定金额。请注意,原始订单行状态不会改变,因为请求是在发票上操作,而不是在订单本身上。
Example (cont. from 6.2.3.2):
4. dResponse3 = WebPay::deliverOrder()->addOrderRows(E)->setCreditInvoice(invoice1)...->doRequest();
//To credit i.e. 50% of the price for order row A we created a new order row E with half the price of A.
//The credit invoice id is returned in dResponse3->getInvoiceId()
6.3 WebPay::getAddresses()
WebPay::getAddresses() 入口用于获取与给定客户身份关联的有效地址列表。此列表可以进一步用于验证订单配送地址是否与Svea用于发票和分期付款订单的发票地址匹配。仅适用于SE、NO和DK的客户。请注意,在挪威,仅支持公司客户。
使用WebPay::getAddresses入口获取请求类实例,然后提供有关交易的信息,并使用请求类方法发送请求。
使用setCountryCode()提供与用于地址查找的账户凭证相对应的国家代码。请注意,这意味着您无法在外国查找用户,这是由于发票和分期付款方式不支持外国订单的结果。
使用setCustomerIdentifier()提供根据国家识别客户的准确凭证:* SE:Personnummer(私人个体)或Organisationsnummer(公司/法律实体)* NO:Organisasjonsnummer(公司或其他法律实体)* DK:Cpr.nr(私人个体)或CVR-nummer(公司或其他法律实体)
然后根据要查找的客户类型使用getIndividualAddresses()或getCompanyAddresses()。
最终的doRequest()会将getAddresses请求发送到Svea并返回结果。
doRequest()方法将检查在给定的configurationProvider中是否存在用于请求的凭证。
(请注意,如果您的集成设置为使用不同的(测试/生产)凭证进行发票和分期付款,这种行为可能会导致问题——如果您收到错误并且是这种情况,您可以使用已弃用的方法setOrderTypeInvoice()或setOrderTypePaymentPlan()来明确指定要使用的凭证方法。)
<?php ... $request = WebPay::getAddresses($config) ->setCountryCode() // required -- the country to perform the customer address lookup in ->setCustomerIdentifier() // required -- social security number, company vat number etc. used to identify customer ->setOrderTypeInvoice() // deprecated -- method that corresponds to the ConfigurationProvider account credentials used ->setOrderTypePaymentPlan() // deprecated -- method that corresponds to the ConfigurationProvider account credentials used ; // then select the corresponding request class and send request $response = $request->getIndividualAddresses()->doRequest(); // returns GetAddressesResponse $response = $request->getCompanyAddresses()->doRequest(); // returns GetAddressesResponse
6.3.1 getAddresses响应格式
Webpay::getAddresses请求返回一个GetAddressesResponse实例,其中包含实际的客户地址,在GetAddressIdentity数组中。
<?php ... $myGetAddressResponse = WebPay::getAddresses($myConfig); // GetAddressResponse attributes: $myGetAddressResponse->accepted; // Boolean // true iff request was accepted $myGetAddressResponse->resultcode; // String // set iff accepted false $myGetAddressResponse->errormessage; // String // set iff accepted false $myGetAddressResponse->customerIdentity; // Array of GetAddressIdentity $firstCustomerAddress = $myGetAddressesResponse->customerIdentity[0]; // GetAddressIdentity attributes: $firstCustomerAddress->customerType; // String // "Person" or "Business" for individual and company customers, respectively $firstCustomerAddress->nationalIdNumber; // Numeric // national id number of individual or company $firstCustomerAddress->fullName; // String // amalgamated firstName and surname for individual, or company name for company customers $firstCustomerAddress->coAddress; // String // optional $firstCustomerAddress->street; // String // required, streetName including houseNumber $firstCustomerAddress->zipCode; // String // required $firstCustomerAddress->locality; // String // required, city name $firstCustomerAddress->phoneNumber; // String // optional $firstCustomerAddress->firstName; // String // optional, present in GetAddressResponse, not returned in CreateOrderResponse $firstCustomerAddress->lastName; // String // optional, present in GetAddressResponse, not returned in CreateOrderResponse $firstCustomerAddress->addressSelector; // String // optional, uniquely disambiguates company addresses ...
如果定义,客户fullName
方法将包含由我们各自国家使用的各种信用提供商返回的客户firstName和surname的合并。不幸的是,没有方法知道合并名称的确切格式;例如,“Joan Doe”、“Joan, Doe”、“Doe, Joan”。
6.3.2 getAddresses请求示例(新样式)
<?php $request = WebPay::getAddresses($config) ->setCountryCode() // required -- the country to perform the customer address lookup in ->setCustomerIdentifier() // required -- social security number, company vat number etc. used to identify customer ->setOrderTypeInvoice() // deprecated -- method that corresponds to the ConfigurationProvider account credentials used ->setOrderTypePaymentPlan() // deprecated -- method that corresponds to the ConfigurationProvider account credentials used ; // then select the corresponding request class and send request $response = $request->getIndividualAddresses()->doRequest(); // returns GetAddressesResponse $response = $request->getCompanyAddresses()->doRequest(); // returns GetAddressesResponse
6.3.3 getAddresses请求示例
<?php $response = WebPay::getAddresses( $config ) ->setCountryCode("SE") // Required -- supply the country code that corresponds to the account credentials used ->setOrderTypeInvoice() // Required -- use invoice account credentials for getAddresses lookup ->setCustomerIdentifier("194605092222") // Required -- lookup the address ->getIndividualAddresses() // get private individual address ->doRequest(); ;
完整的用法示例可以在example/config_getaddresses文件夹中找到。
6.4 WebPay::getPaymentPlanParams()
使用getPaymentPlanParams()在创建分期付款支付之前获取与给定客户号关联的所有活动。
<?php ... $response = WebPay::getPaymentPlanParams($config) ->setCountryCode("SE") // Required ->doRequest(); ...
响应是一个WebService\PaymentPlanParamsResponse实例,其中包含在campaignCodes数组中的可用活动。
<?php ... $response->accepted // true if request was accepted by the service $response->errormessage // may be set if accepted above is false $response->resultcode // 27xxx, reason $response->campaignCodes[] // array of all available campaign payment plans in an array ->campaignCode // numeric campaign code identifier ->description // localised description string ->paymentPlanType // human readable identifier (not guaranteed unique) ->contractLengthInMonths ->monthlyAnnuityFactor // pricePerMonth = price * monthlyAnnuityFactor + notificationFee ->initialFee ->notificationFee ->interestRatePercent ->numberOfInterestFreeMonths ->numberOfPaymentFreeMonths ->fromAmount // amount lower limit for plan availability ->toAmount // amount upper limit for plan availability ...
6.5 WebPay::paymentPlanPricePerMonth()
这是一个辅助函数,用于计算给定金额的不同分期付款选项的每月价格。这些信息可用于在结账时显示支付选项,或显示产品级别上每月最低应付款项。
返回的PaymentPlanPricePerMonth实例包含一个"values"数组,其中每个元素又包含一个包含活动代码、描述和每月价格的数组。
6.6 WebPay::listPaymentMethods()
WebPay::listPaymentMethods方法用于获取针对给定国家配置的所有可用支付方式。
6.6.1 用法
使用WebPay::listPaymentMethods()入口获取ListPaymentMethods实例。然后提供有关交易的信息,并使用ListPaymentMethod方法发送请求。
<?php ... $methods = WebPay::listPaymentMethods( $config ) ->setCountryCode("SE") // required ->doRequest() ; ...
在调用->doRequest之后,您将收到一个ListPaymentMethodsResponse实例。
6.7 WebPay::getAccountCreditParams()
WebPay::getAccountCreditParams 方法用于获取配置国家所有可用的活动。
6.7.1 使用方法
<?php ... $campaigns = WebPay::getAccountCreditParams( $config ) ->setCountryCode('SE') // required ->doRequest(); ...
在调用 ->doRequest 后,您将收到一个 AccountCreditParamsResponse 实例。
6.8 WebPay::checkout()
WebPay::checkout 方法用于调用所有可用的 Svea Checkout 功能。
6.8.1 创建订单
使用 WebPay::checkout()->createOrder() 方法创建新的 Checkout 订单。
<?php ... $order = WebPay::checkout($config) ->addOrderRow($orderRow) // required, see WebPayItem::orderRow ->addFee($shippingFee) // optional, see WebPayItem for shipping fee ->addDiscount($discount) // optional, see WebPayItem for fixed discount ->setCountryCode("SE") // required for Svea Checkout ->setCurrency("SEK") // required for Svea Checkout ->setCheckoutUri("https://:51925/") // required Merchant settings (checkout uri) ->setConfirmationUri("https://:51925/checkout/confirm") // required Merchant settings (confirmation uri) ->setPushUri("https://svea.com/push.aspx?sid=123&svea_order=123") // required Merchant settings (push uri) ->setTermsUri("https://:51898/terms") // required Merchant settings (terms uri) ->setValidationCallbackUri('https://:51898/validation-callback') // optional Merchant settings (validation uri) ->setPartnerKey('77FB33EC-505D-4CCF-AA21-D9DF50DC8344') // optional GUID for partners to Svea, leave blank if you're unsure what this does ->setRequireElectronicIdAuthentication(true) // optional, force electronic id authentication when customer finalizes order ->setLocale('sv-SE') // required for Svea Checkout ->createOrder() // Create new Checkout order ; ...
如果您是需要 partnerKey 的合作伙伴,请联系 Svea,partnerKey 不是必需的,但它有助于跟踪双方商家的统计数据。
6.7.2 从订单中获取信息
使用 WebPay::checkout()->getOrder() 方法获取现有的 Checkout 订单信息。
<?php ... $locale = 'sv-SE'; $order = WebPay::checkout($config) ->setCountryCode('SE') // required locale field ->setCheckoutOrderId(50) // required Checkout order ID ->getOrder() // Get existing Checkout order ; ...
6.7.3 更新订单
使用 WebPay::checkout()->updateOrder() 方法更新现有的 Checkout 订单。
<?php ... $locale = 'sv-SE'; $order = WebPay::checkout($config) ->setCountryCode('SE') // required locale field ->setCheckoutOrderId(50) // required Checkout order ID ->addOrderRow($orderRow) // see WebPayItem::orderRow ->updateOrder(); // Update existing Checkout order ...
7. WebPayAdmin 入口点方法参考
WebPayAdmin 类方法用于在订单被 Svea 接受后进行管理。它包括更新、交付、取消和冲正订单等功能。
在管理通过 checkout 制作的订单时,您设置 CheckoutOrderId 而不是使用 sveaOrderId 或 TransactionID。使用 7.3 WebPayAdmin::queryOrder 来找出可以在 checkout 订单上执行的操作。以下示例假设可以在该订单上执行该操作。
所有 checkout 的响应对象都可以在 连接库 中找到。
请参阅示例文件夹中的所有完整示例。
- 7.1 WebPayAdmin::queryTaskInfo
- 7.2 WebPayAdmin::cancelOrder()
- 7.3 WebPayAdmin::queryOrder()
- 7.4 WebPayAdmin::cancelOrderRows()
- 7.5 WebPayAdmin::creditOrderRows()
- 7.6 WebPayAdmin::addOrderRows()
- 7.7 WebPayAdmin::updateOrderRows()
- 7.8 WebPayAdmin::deliverOrderRows()
- 7.9 WebPayAdmin::updateOrder()
- 7.10 WebPayAdmin::creditAmount()
- 7.11 WebPayAdmin::creditOrderRows()
7.1 WebPayAdmin::queryTaskInfo()
WebPayAdmin::queryTaskInfo() 用于说明之前执行的操作的状态。完成后,它将通过 Location 指向新的资源。
响应将包含有关任务的信息,以及一个包含排队任务详细信息的对象。
<?php ... $taskUrl = 'http://paymentadminapi.svea.com/api/v1/queue/1'; $response = WebPayAdmin::queryTaskInfo($testConfig) ->setTaskUrl($taskUrl) ->getTaskInfo() ->doRequest(); ...
7.2 WebPayAdmin::cancelOrder()
WebPayAdmin::cancelOrder() 入口点方法用于取消尚未交付(发票、分期付款)或确认(卡)的 Svea 订单。
支持发票、分期付款、卡订单以及使用这些付款方式在 checkout 中制作的订单。
直接银行订单需要冲正,请参阅 7.5 WebPayAdmin::creditOrderRows()。
使用 WebPayAdmin.cancelOrder 入口点获取实例,然后提供更多有关订单的信息,并使用 CancelOrderBuilder 方法发送请求。
<?php ... $request = WebPayAdmin->cancelOrder($config) ->setOrderId() // required for invoice and payment plan orders, use SveaOrderId received with createOrder response ->setTransactionId() // required for card orders only ->setCountryCode() // required, use same country code as in createOrder request ->setCheckoutOrderId() // required for checkout orders ; // then select the corresponding request class and send request $response = $request->cancelInvoiceOrder()->doRequest(); // returns CloseOrderResponse $response = $request->cancelPaymentPlanOrder()->doRequest(); // returns CloseOrderResponse $response = $request->cancelCardOrder()->doRequest(); // returns AnnulTransactionResponse $response = $request->cancelCheckoutOrder()->doRequest(); // returns empty content for valid response $response = $request->cancelAccountCreditOrder()->doRequest(); // returns CloseOrderResponse ...
对于 Checkout,cancelOrder() 支持取消订单的金额。
... $request = WebPayAdmin::cancelOrder($testConfig) ->setCheckoutOrderId($sveaCheckoutOrderId) ->setAmountIncVat(5.00) ->cancelCheckoutOrderAmount(); $response = $request->doRequest(); ...
7.3 WebPayAdmin::queryOrder()
WebPayAdmin::queryOrder 入口点方法用于获取有关订单的信息。
注意,对于发票和分期付款订单,订单行名称和描述合并到查询响应的描述字段中。
使用 WebPayAdmin::queryOrder 入口点获取实例,然后提供更多有关订单的信息,并使用 QueryOrderBuilder 方法发送请求。
<?php ... $request = WebPayAdmin::queryOrder($config) ->setOrderId() // required for invoice and payment plan orders, use SveaOrderId received with createOrder response ->setTransactionId() // required for card orders only ->setClientOrderNumber() // optional, can be used instead of ->setTransactionId() ->setCountryCode() // required, use same country code as in createOrder request ->setCheckoutOrderId() // required for checkoutOrder ; // then select the corresponding request class and send request $response = $request->queryInvoiceOrder()->doRequest(); // returns GetOrdersResponse $response = $request->queryPaymentPlanOrder()->doRequest(); // returns GetOrdersResponse $response = $request->queryCardOrder()->doRequest(); // returns QueryTransactionResponse $response = $request->queryDirectBankOrder()->doRequest(); // returns QueryTransactionResponse $response = $request->queryCheckoutOrder()->doRequest(); // returns formatted array response with order information $response = $request->queryAccountCreditOrder()->doRequest(); // returns GetOrderResponse ...
7.3.1 查询订单示例
使用 setName() 和 setDescription() 指定订单行的订单示例
<?php ... $orderRow = WebPayItem::orderRow() ... ->setName("orderrow 1") // optional ->setDescription("description 1") // optional ; $order->addOrderRow($orderRow)->useInvoicePayment()->doRequest(); ...
查询上述订单将导致具有以下名称和描述的订单行响应
<?php ... $queryBuilder = WebPayAdmin::queryOrder($config) ->setOrderId($invoiceOrderIdToQuery) ->setCountryCode($country) ; $queryInvoiceOrderResponse = $queryBuilder->queryInvoiceOrder()->doRequest(); $queryInvoiceOrderResponse->name; // contains null $queryInvoiceOrderResponse->description; // contains "orderrow 1: description 1"
而以相同方式指定的卡、直接银行或 checkout 订单将具有
<?php ... $queryOrderResponse->name; // contains "orderrow 1" $queryOrderResponse->description; // contains "description 1"
如您所见,订单行名称字段存在,但在 GetOrdersResponse 类中始终为 null。这是正确的,并且是由于响应重用了现有的 NumberOrderRow 类。QueryOrderResponse 在相应的字段中有原始的名称和描述。
QueryCheckoutOrder() 仅用于通过结账方式创建的订单。
7.4 WebPayAdmin::cancelOrderRows()
WebPayAdmin::cancelOrderRows 入口方法用于在订单发货前取消订单行。支持发票、支付计划、卡订单以及使用这些支付方式在结账时创建的订单。(不支持直接银行订单,请参阅CreditOrderRows。)
对于发票和支付计划订单,每次成功请求后,订单行状态都会在Svea更新。
对于卡订单,请求只能发送一次,如果所有原始订单行都已取消,则在Svea的订单状态将变为“已取消”。
使用WebPayAdmin.cancelOrderRows入口点获取订单构建器实例,然后使用CancelOrderRowsBuilder方法提供有关交易的更多信息并发送请求。
使用setRowToCancel()或setRowsToCancel()指定要取消的订单行。订单行索引应与WebPayAdmin::queryOrder()等返回的索引相对应。
对于卡订单,使用addNumberedOrderRow()或addNumberedOrderRows()传入原始订单行的副本。可以使用WebPayAdmin::queryOrder()检索原始订单行;numberedOrderRows属性包含带索引的服务器端订单行。请注意,如果卡订单在初始订单创建后已被修改(即行取消或贷记),则返回的订单行可能不准确。
<?php ... $request = WebPayAdmin::cancelOrderRows($config) ->setOrderId() // required for invoice and payment plan orders, use SveaOrderId received with createOrder response ->setTransactionId() // required for card orders only ->setCountryCode() // required, use same country code as in createOrder request ->setCheckoutOrderId() // required for checkoutOrder ->setRowToCancel() // required, index of original order rows you wish to cancel ->addNumberedOrderRow() // required for card orders, should match original row indexes ; // then select the corresponding request class and send request $response = $request->cancelInvoiceOrderRows()->doRequest(); // returns CancelOrderRowsResponse $response = $request->cancelPaymentPlanOrderRows()->doRequest(); // returns CancelOrderRowsResponse $response = $request->cancelCardOrderRows()->doRequest(); // returns LowerTransactionResponse $response = $request->cancelCheckoutOrderRows()->doRequest(); // returns no content if response is success ...
有关取消结账订单行的示例,请参阅example/checkout/admin/credit-order-rows.php。
7.5 WebPayAdmin::creditOrderRows()
WebPayAdmin::creditOrderRows入口方法用于在订单发货后贷记订单行。支持所有支付方式。(要贷记支付计划订单,请首先联系Svea客户服务。)
如果您希望贷记原始订单中未出现的金额,请使用addCreditOrderRow()或addCreditOrderRows()并提供要贷记的金额的新订单行。这是贷记卡或直接银行订单的推荐方法。
如果您希望全额贷记发票或支付计划订单行,您可以使用setRowToCredit()指定要贷记的订单行索引。相应的Svea订单行将被贷记。(对于卡或直接银行订单,您需要首先查询,然后使用addNumberedOrderRows()方法提供相应的编号订单行。)
* Following the request Svea will issue a credit invoice including the original order rows specified using setRowToCredit(),
* as well as any new credit order rows specified using addCreditOrderRow(). For card or direct bank orders, the order row amount
* will be credited to the customer.
使用WebPayAdmin::creditOrderRows入口点获取订单构建器实例,然后提供有关交易的更多信息并使用creditOrderRowsBuilder方法发送请求。
<?php ... $request = WebPayAdmin::creditOrderRows($config) ->setCheckoutOrderId() // required for checkout orders ->setDeliveryId() // required for checkout orders, found in the response from a delivery action ->setInvoiceId() // required for invoice ->setInvoiceDistributionType() // required for invoice ->setContractNumber() // required for payment plan ->setOrderId() // required for card, direct bank and accountCredit ->setCountryCode() // required ->addCreditOrderRow() // optional, use to specify a new credit row, i.e. for amounts not present in the original order ->addCreditOrderRows() // optional ->setRowToCredit() // optional, index of one of the original order row you wish to credit ->setRowsToCredit() // optional, list of row indexes you wish to credit ->addNumberedOrderRow() // card and direct bank only, required with setRowToCredit() ->addNumberedOrderRows() // card and direct bank only, optional ; // then select the corresponding request class and send request $response = $request->creditInvoiceOrderRows()->doRequest(); // returns CreditInvoiceRowsResponse $response = $request->creditPaymentplanOrderRows()->doRequest(); // returns CreditOrderRowsRequest $response = $request->creditCardOrderRows()->doRequest(); // returns CreditTransactionResponse $response = $request->creditDirectBankOrderRows()->doRequest(); // returns CreditTransactionResponse $response = $request->creditCheckoutOrderRows()->doRequest(); $response = $request->creditAccountCreditOrderRows()->doRequest(); // returns CreditIOrderRowsResponse ...
7.5.1 用法
WebPayAdmin::creditOrderRows入口方法用于在订单发货后贷记订单行。支持所有支付方式。
要全额贷记订单行,您指定要贷记的订单行索引(对于卡订单,还需要提供编号订单行数据本身)。
如果您希望贷记原始订单中未出现的金额,您需要使用addCreditOrderRow()或addCreditOrderRows()提供贷记金额的新订单行。这些行将在以下setRow(s)ToCredit指定的任何行之外进行贷记。
在贷记结账时创建的订单时使用setCheckoutOrderId()。
使用setInvoiceId()指定要贷记的发票(已发货订单)。
使用setContractNumber()指定要贷记的支付计划合同(已发货订单)。(实际上这实际上意味着取消合同中的订单行)
使用setOrderId()指定要贷记的卡或直接银行交易(已发货订单)。
使用 setCountryCode() 指定与原始创建订单请求匹配的国家/地区代码。
使用setRowToCredit()或setRowsToCredit()指定要贷记的订单行。给定的行号必须与服务器端行号相对应。
对于卡或直接银行订单,必须使用addNumberedOrderRow()或addNumberedOrderRows()传入服务器端订单行数据的副本。
您可以使用 WebPayAdmin::queryOrder() 入口来获取订单信息,queryOrder 响应的 numberedOrderRows 属性包含带有数字的订单行。订单行将按它们设置的顺序排列,因此您也可以在创建订单请求时保存订单行号,并为此目的使用。对于发票订单,在 creditOrderRows 请求后,服务器端订单行将被更新。请注意,对于卡和直接银行订单,服务器端订单行不会更新。
然后使用 creditInvoiceOrderRows()、creditAccountCreditOrderRows()、creditPaymentPlanOrderRows()、creditCardOrderRows() 或 creditDirectBankOrderRows() 获取请求对象,该对象与原始订单中使用的支付方式相匹配。
在请求对象上调用 doRequest() 将请求发送到 Svea,并返回 CreditOrderRowsResponse 或 CreditTransactionResponse。
7.6 WebPayAdmin::addOrderRows()
WebPayAdmin::addOrderRows 方法用于向非交付的发票、支付计划订单以及使用这些支付方式的结账订单添加单个订单行。
7.6.1 使用方法
向订单添加订单行。支持使用这些支付方式开具发票、支付计划和结账订单。(不支持卡和直接银行订单。)
提供有关新订单行信息,并使用 addOrderRowsBuilder 方法发送请求
<?php ... $request = WebPayAdmin::addOrderRows($testConfig) ->setCheckoutOrderId() // Required for checkout orders ->setOrderId() // Required for invoice or payment plan ->setCountryCode() ->addOrderRow() // One or more, for checkout is limit only one row ->addOrderRows() // optional //Finish by selecting the correct orderType and perform the request: $response = $request->addInvoiceOrderRows()->doRequest(); $response = $request->addPaymentPlanOrderRows()->doRequest(); $response = $request->addCheckoutOrderRows()->doRequest(); ...
7.7 WebPayAdmin::updateOrderRows()
WebPayAdmin::updateOrderRows() 方法用于更新非交付的发票和支付计划订单中的单个订单行。
支持使用这些支付方式开具发票、支付计划和结账订单。
订单行状态在 Svea 更新以反映更新的订单行。如果更新的行订单总金额超过原始订单总金额,服务将返回错误。
使用 WebPayAdmin::updateOrderRows() 入口获取订单构建器实例,然后提供有关交易的更多信息,并使用 UpdateOrderRowsBuilder 方法发送请求
使用 setCountryCode() 指定与原始创建订单请求匹配的国家/地区代码。
使用 updateOrderRow() 和新的 WebPayItem::numberedOrderRow() 对象传递更新的订单行。使用 NumberedOrderRowBuilder 成员函数指定更新的订单行内容。值得注意的是,setRowNumber() 方法指定要完全替换哪个原始订单行内容。
然后使用 updateInvoiceOrderRows() 或 updatePaymentPlanOrderRows() 获取请求对象,该对象与原始订单中使用的支付方式相匹配。
在请求对象上调用 doRequest() 将请求发送到 Svea 并返回 UpdateOrderRowsResponse。
<?php ... $request = WebPayAdmin::updateOrderRows($config) ->setCheckoutOrderId() // required if it's a checkout order ->setOrderId() // required if it's not a checkout order ->setCountryCode() // required ->updateOrderRow() // required, NumberedOrderRow w/RowNumber attribute matching row index of original order row // then select the corresponding request class and send request $response = $request->updateInvoiceOrderRows()->doRequest(); // returns UpdateOrderRowsResponse $response = $request->updatePaymentPlanOrderRows()->doRequest(); // returns UpdateOrderRowsResponse $response = $request->updateCheckoutOrderRows()->doRequest(); ...
有关在结账订单中更新订单行的示例,请参阅 example/checkout/admin/update-order-rows.php。
7.8 WebPayAdmin::deliverOrderRows()
WebPayAdmin::deliverOrderRows 入口方法用于交付单个订单行。支持发票和卡订单。(要部分交付支付计划或直接银行订单,请联系 Svea。)该方法还支持使用发票或卡进行的结账订单。
对于发票订单,每次成功请求后,在 Svea 更新订单行状态。
对于卡订单,订单只能交付一次,任何未交付的订单行将被取消(即订单金额将减少未交付订单行的总和)。已交付的卡订单在 Svea 的状态为 CONFIRMED。
使用 WebPayAdmin::deliverOrderRows 入口获取订单构建器实例,然后提供有关交易的更多信息,并使用 DeliverOrderRowsBuilder 方法发送请求
使用 setRowToDeliver() 或 setRowsToDeliver() 指定要交付的订单行。订单行索引应与例如 WebPayAdmin::queryOrder() 返回的索引相对应。
对于卡订单,使用addNumberedOrderRow()或addNumberedOrderRows()传入原始订单行的副本。可以使用WebPayAdmin::queryOrder()检索原始订单行;numberedOrderRows属性包含带索引的服务器端订单行。请注意,如果卡订单在初始订单创建后已被修改(即行取消或贷记),则返回的订单行可能不准确。
<?php ... $request = WebPayAdmin::deliverOrderRows($config) ->setCheckoutOrderId() // required if order is made using the checkout ->setOrderId() // required if order is invoice and isn't made in the checkout ->setTransactionId() // required if order is card and isn't made in the checkout ->setCountryCode() // required ->setInvoiceDistributionType() // required for invoice only ->setRowToDeliver() // required, index of original order rows you wish to deliver ->addNumberedOrderRow() // required for card orders, should match original row indexes ; // then select the corresponding request class and send request $response = $request->deliverInvoiceOrderRows()->doRequest(); // returns DeliverOrderRowsResponse $response = $request->deliverPaymentPlanOrderRows()->doRequest(); // returns DeliverOrderRowsResponse $response = $request->deliverCardOrderRows()->doRequest(); // returns ConfirmTransactionResponse $response = $request->deliverCheckoutOrderRows()->doRequest(); ...
7.9 WebPayAdmin::updateOrder()
WebPayAdmin::updateOrder() 方法用于添加或更改 ClientOrderNumber 和/或备注。支持发票和支付计划订单。
使用 WebPayAdmin::updateOrder() 入口获取订单构建器实例,然后提供有关交易的更多信息,并使用 UpdateOrderBuilder 方法发送请求
使用setCountryCode()指定与原始创建订单请求匹配的国家代码。使用setOrderId()指定要使用的订单。如果想要添加或更改客户端订单号,请使用setClientOrderNumber()。如果想要添加或更改客户发票上的备注,请使用setNotes()。然后使用updateInvoiceOrder()或updatePaymentPlanOrder()来获取请求对象,该对象匹配原始订单中使用的支付方式。
在请求对象上调用doRequest()会将请求发送到Svea并返回UpdateOrderResponse。
<?php ... $request = WebPayAdmin::updateOrder($config) ->setOrderId() // required for invoice and payment plan orders made without the checkout ->setCountryCode() // required ->setClientOrderNumber() // optional String(32) ->setNotes() // optional String(200) ; // then select the corresponding request class and send request $response = $request->updateInvoiceOrder()->doRequest(); // returns UpdateOrderResponse $response = $request->updatePaymentPlanOrder()->doRequest(); // returns UpdateOrderResponse ...
7.10 WebPayAdmin::creditAmount()
如果您希望在结账订单中扣除金额,请参阅7.10.1 结账订单中的扣除金额。
WebPayAdmin::creditAmount()入口方法用于在订单发货后扣除金额。支持分期付款。
使用WebPayAdmin::creditAmount入口点获取订单构建器实例,然后提供有关交易的更多信息,并使用CreditAmountBuilder方法发送请求。
<?php ... $request = WebPayAdmin::creditAmount($config) ->setContractNumber(12345) ->setCountryCode('SE') ->setDescription('credit desc') ->setAmountIncVat(1500.00); $response = $request->creditPaymentPlanAmount()->doRequest(); ...
7.10.1 结账订单中的扣除金额
WebPayAdmin::creditAmount()入口点方法用于在订单发货后扣除金额。
使用WebPayAdmin::creditAmount入口点获取订单构建器实例,然后提供有关交易的更多信息,并使用CreditAmountBuilder方法发送请求。
<?php ... $request = WebPayAdmin::creditAmount($myConfig) ->setCheckoutOrderId($sveaCheckoutOrderId) // required ->setDeliveryId(1) // required for checkout orders, found in the response from a delivery action ->setAmountIncVat(20.00) ->creditCheckoutAmount() ->doRequest(); ...
7.11 WebPayAdmin::creditOrderRows()
WebPayAdmin::creditOrderRows用于扣除单个订单行或多个订单行。
<?php ... $creditOrderRowsBuilder = WebPayAdmin::creditOrderRows($testConfig) ->setCheckoutOrderId($sveaCheckoutOrderId) // Set the checkout order id ->setDeliveryId(1) // required for checkout orders, found in the response from a delivery action ->setRowsToCredit(2); // This will credit the second order row, can also be an array of rows $response = $creditOrderRowsBuilder->creditCheckoutOrderRows()->doRequest(); ...
7.11.1 使用新的订单行进行扣除
如果您想要创建一个新订单行,在该订单行中指定将要扣除的金额,您可以通过将WebPayItem::orderRow()添加到WebPayAdmin::creditOrderRows()方法中来实现,如下例所示
<?php ... $creditOrderRowsBuilder = WebPayAdmin::creditOrderRows($testConfig) ->setCheckoutOrderId($sveaCheckoutOrderId) ->setDeliveryId(1) // required for checkout orders, found in the response from a delivery action $myCreditRow = WebPayItem::orderRow() ->setAmountIncVat(300.00) ->setVatPercent(25) ->setQuantity(1) ->setDescription("Credited order with new Order row"); $creditOrderRowsBuilder->addCreditOrderRow($myCreditRow); $response = $creditOrderRowsBuilder->creditCheckoutOrderWithNewOrderRow()->doRequest(); ...
7.12 WebPayAdmin::cancelRecurSubscription()
WebPayAdmin::cancelRecurSubscription()用于使现有的重复订阅失效,以便无法再次进行重复操作。
<?php $config = ConfigurationService::getTestConfig(); $request = WebpayAdmin::cancelRecurSubscription($config) ->setCountryCode("SE") ->setSubscriptionId("123456") ->cancelRecurSubscription() ->doRequest();
8. SveaResponse和响应类
所有同步支付响应都返回一个SveaResponse对象。
所有来自支付网关的异步响应返回xml,但可以通过SveaResponse类进行解析和MAC验证。
所有 checkout 的响应对象都可以在 连接库 中找到。
8.1 解析异步服务响应
所有同步支付服务请求响应都由SveaResponse解析,并由请求方法本身结构化为响应对象。对于同步服务请求,您不需要调用SveaResponse对象。
异步支付请求响应(即卡和直接银行支付)需要在监听指定请求返回url的页面上进行处理。响应包含参数:response、merchantId和mac,其中响应是一个Base64编码的消息。使用SveaResponse类的实例,而不是获取类似于同步服务响应的结构化对象。
8.1.1
首先,创建一个SveaResponse实例,将其作为$_REQUEST响应的一部分传递给结果xml响应,同时传递一个ConfigurationProvider和国家代码,然后通过调用getResponse()方法接收一个HostedResponse实例,传递给返回url的消息、请求国家代码和配置。以下是处理$_REQUEST全局变量中接收到的响应的示例
<?php ... $response = (new SveaResponse($_REQUEST,$countryCode,$config))->getResponse(); ...
8.1.2
异步(卡)订单的示例可以在example/cardorder文件夹中找到。
8.2 响应已接受和结果代码
在集成包中,所有服务响应对象都实现了以下属性,这些属性可用于确定请求的结果
accepted
-- 如果设置为逻辑真,表示请求已被Svea接受resultcode
-- 如果设置为大于0的值,表示服务请求存在问题errormessage
-- 结果代码的易读版本,仅在resultCode大于0时设置
由于来自各种Svea Web服务的请求响应在实现上有所不同,我们强烈建议,例如,检查“accepted”属性是否为逻辑真,而不是检查它是否包含特定的值或类型。即使用: "if( $response->accepted == true )" 而不是 "if( $response->accepted === 1)" 或 "if( $response->accepted > 0)" 等。
请参阅相应的响应类以获取有关响应属性、可能的返回代码等信息。
9. 辅助类及附加开发者资源和注释
在辅助类中,我们提供了辅助函数,例如,银行四舍五入、获取订单对象中存在的不同税率、将订单行按任意平均税率分割成一个或两个具有给定税率的新的订单行,以及将街道地址分割成街道名称和门牌号。有关更多信息,请参阅辅助类定义。
9.1 PaymentPlanCalculator
PaymentPlanCalculator类包含几个静态方法,这些方法对计算与支付计划活动相关的金额非常有用
该类可以
- 获取单个活动的总支付金额
- 获取单个活动的每月支付金额
- 获取单个活动的实际利率
- 在一个方法中获取单个活动的总支付金额、每月支付金额和实际利率
- 获取多个活动的总支付金额
- 获取多个活动的每月支付金额
- 获取多个活动的实际利率
- 在一个方法中获取多个活动的总支付金额、每月支付金额和实际利率
所有方法中的活动参数都支持WebPay::getPaymentPlanParams响应对象中的类成员“campaignCodes”,以及用于从结账商家获取活动的GetAvailablePartPaymentCampaigns响应。
如果使用“CampaignCodeInfo”数组,则数组键的第一个字母将小写,否则第一个字母将大写。
当获取所有活动时,可以选择传递参数$ignoreMinMaxFlag,默认为false。如果为true,则无论订单总额是否适合该活动,都将返回所有活动。
9.1.1 获取单个活动的总支付金额
输入
<?php require_once 'path/to/vendor/autoloader/'; use \Svea\WebPay\Helper\PaymentPlanHelper\PaymentPlanCalculator; $orderTotal = 11200; $decimals = 0; // This parameter is optional and will default to 0, use 2 decimals if payments are in euro $campaign = array ( 'CampaignCode' => 213060, 'Description' => 'Dela upp betalningen på 60 månader', 'PaymentPlanType' => 0, 'ContractLengthInMonths' => 60, 'MonthlyAnnuityFactor' => 0.02555, 'InitialFee' => 100.0, 'NotificationFee' => 29.0, 'InterestRatePercent' => 16.75, 'NumberOfInterestFreeMonths' => 3, 'NumberOfPaymentFreeMonths' => 3, 'FromAmount' => 1000.0, 'ToAmount' => 50000.0 ); $totalAmountToBePayed = PaymentPlanCalculator::getTotalAmountToPay($orderTotal, $campaign, $decimals); echo $totalAmountToBePayed;
输出
18067
9.1.2 获取单个活动的每月支付金额
输入
<?php require_once 'path/to/vendor/autoloader/'; use \Svea\WebPay\Helper\PaymentPlanHelper\PaymentPlanCalculator; $orderTotal = 11200; $decimals = 0; // This parameter is optional and will default to 0, use 2 decimals if payments are in euro $campaign = array ( 'CampaignCode' => 213060, 'Description' => 'Dela upp betalningen på 60 månader', 'PaymentPlanType' => 0, 'ContractLengthInMonths' => 60, 'MonthlyAnnuityFactor' => 0.02555, 'InitialFee' => 100.0, 'NotificationFee' => 29.0, 'InterestRatePercent' => 16.75, 'NumberOfInterestFreeMonths' => 3, 'NumberOfPaymentFreeMonths' => 3, 'FromAmount' => 1000.0, 'ToAmount' => 50000.0 ); $monthlyAmount = PaymentPlanCalculator::getMonthlyAmountToPay($orderTotal, $campaign, $decimals); echo $monthlyAmount;
输出
317
9.1.3 获取单个活动的实际利率
输入
<?php require_once 'path/to/vendor/autoloader/'; use \Svea\WebPay\Helper\PaymentPlanHelper\PaymentPlanCalculator; $orderTotal = 11200; $decimals = 0; // This parameter is optional and will default to 0, use 2 decimals if payments are in euro $campaign = array ( 'CampaignCode' => 213060, 'Description' => 'Dela upp betalningen på 60 månader', 'PaymentPlanType' => 0, 'ContractLengthInMonths' => 60, 'MonthlyAnnuityFactor' => 0.02555, 'InitialFee' => 100.0, 'NotificationFee' => 29.0, 'InterestRatePercent' => 16.75, 'NumberOfInterestFreeMonths' => 3, 'NumberOfPaymentFreeMonths' => 3, 'FromAmount' => 1000.0, 'ToAmount' => 50000.0 ); $effectiveInterestRate = PaymentPlanCalculator::getEffectiveInterestRate($orderTotal, $campaign, $decimals); echo $effectiveInterestRate;
输出
21.33
9.1.4 获取单个活动的所有计算结果
输入
<?php require_once 'path/to/vendor/autoloader/'; use \Svea\WebPay\Helper\PaymentPlanHelper\PaymentPlanCalculator; $orderTotal = 11200; $decimals = 0; // This parameter is optional and will default to 0, use 2 decimals if payments are in euro $campaign = array ( 'CampaignCode' => 213060, 'Description' => 'Dela upp betalningen på 60 månader', 'PaymentPlanType' => 0, 'ContractLengthInMonths' => 60, 'MonthlyAnnuityFactor' => 0.02555, 'InitialFee' => 100.0, 'NotificationFee' => 29.0, 'InterestRatePercent' => 16.75, 'NumberOfInterestFreeMonths' => 3, 'NumberOfPaymentFreeMonths' => 3, 'FromAmount' => 1000.0, 'ToAmount' => 50000.0 ); $campaign = PaymentPlanCalculator::getAllCalculations($orderTotal, $campaign, $decimals); echo '<pre>' . print_r($campaign, true) . '</pre>';
输出
Array ( [CampaignCode] => 213060 [Description] => Dela upp betalningen på 60 månader [PaymentPlanType] => 0 [ContractLengthInMonths] => 60 [MonthlyAnnuityFactor] => 0.02555 [InitialFee] => 100 [NotificationFee] => 29 [InterestRatePercent] => 16.75 [NumberOfInterestFreeMonths] => 3 [NumberOfPaymentFreeMonths] => 3 [FromAmount] => 1000 [ToAmount] => 50000 [EffectiveInterestRate] => 21.33 [MonthlyAmountToPay] => 317 [TotalAmountToPay] => 18067 )
9.1.5 获取多个活动的总支付金额
输入
<?php require_once 'path/to/vendor/autoloader/'; use \Svea\WebPay\Helper\PaymentPlanHelper\PaymentPlanCalculator; $orderTotal = 11200; $decimals = 0; // This parameter is optional and will default to 0, use 2 decimals if payments are in euro $ignoreMinMaxFlag = false; // This parameters is optional and default to false, if set to true it will return all campaigns regardless of if it's valid for the order total $campaigns = array ( 0 => array( 'CampaignCode' => 213060, 'Description' => 'Dela upp betalningen på 60 månader', 'PaymentPlanType' => 0, 'ContractLengthInMonths' => 60, 'MonthlyAnnuityFactor' => 0.02555, 'InitialFee' => 100.0, 'NotificationFee' => 29.0, 'InterestRatePercent' => 16.75, 'NumberOfInterestFreeMonths' => 3, 'NumberOfPaymentFreeMonths' => 3, 'FromAmount' => 1000.0, 'ToAmount' => 50000.0 ), 1 => array ( 'CampaignCode' => 310012, 'Description' => 'Dela upp betalningen på 12 månader (räntefritt)', 'PaymentPlanType' => 1, 'ContractLengthInMonths' => 12, 'MonthlyAnnuityFactor' => 0.08333, 'InitialFee' => 295.0, 'NotificationFee' => 35.0, 'InterestRatePercent' => 0.0, 'NumberOfInterestFreeMonths' => 12, 'NumberOfPaymentFreeMonths' => 0, 'FromAmount' => 1000.0, 'ToAmount' => 30000.0, ) ); $campaigns = PaymentPlanCalculator::getTotalAmountToPayFromCampaigns($orderTotal, $campaigns, $decimals, $ignoreMinMaxFlag); echo '<pre>' . print_r($campaigns, true) . '</pre>';
输出
Array ( [0] => Array ( [CampaignCode] => 213060 [Description] => Dela upp betalningen på 60 månader [PaymentPlanType] => 0 [ContractLengthInMonths] => 60 [MonthlyAnnuityFactor] => 0.02555 [InitialFee] => 100 [NotificationFee] => 29 [InterestRatePercent] => 16.75 [NumberOfInterestFreeMonths] => 3 [NumberOfPaymentFreeMonths] => 3 [FromAmount] => 1000 [ToAmount] => 50000 [TotalAmountToPay] => 18067 ) [1] => Array ( [CampaignCode] => 310012 [Description] => Dela upp betalningen på 12 månader (räntefritt) [PaymentPlanType] => 1 [ContractLengthInMonths] => 12 [MonthlyAnnuityFactor] => 0.08333 [InitialFee] => 295 [NotificationFee] => 35 [InterestRatePercent] => 0 [NumberOfInterestFreeMonths] => 12 [NumberOfPaymentFreeMonths] => 0 [FromAmount] => 1000 [ToAmount] => 30000 [TotalAmountToPay] => 11915 ) )
9.1.6 获取多个活动的每月支付金额
输入
<?php require_once 'path/to/vendor/autoloader/'; use \Svea\WebPay\Helper\PaymentPlanHelper\PaymentPlanCalculator; $orderTotal = 11200; $decimals = 0; // This parameter is optional and will default to 0, use 2 decimals if payments are in euro $ignoreMinMaxFlag = false; // This parameters is optional and default to false, if set to true it will return all campaigns regardless of if it's valid for the order total $campaigns = array ( 0 => array( 'CampaignCode' => 213060, 'Description' => 'Dela upp betalningen på 60 månader', 'PaymentPlanType' => 0, 'ContractLengthInMonths' => 60, 'MonthlyAnnuityFactor' => 0.02555, 'InitialFee' => 100.0, 'NotificationFee' => 29.0, 'InterestRatePercent' => 16.75, 'NumberOfInterestFreeMonths' => 3, 'NumberOfPaymentFreeMonths' => 3, 'FromAmount' => 1000.0, 'ToAmount' => 50000.0 ), 1 => array ( 'CampaignCode' => 310012, 'Description' => 'Dela upp betalningen på 12 månader (räntefritt)', 'PaymentPlanType' => 1, 'ContractLengthInMonths' => 12, 'MonthlyAnnuityFactor' => 0.08333, 'InitialFee' => 295.0, 'NotificationFee' => 35.0, 'InterestRatePercent' => 0.0, 'NumberOfInterestFreeMonths' => 12, 'NumberOfPaymentFreeMonths' => 0, 'FromAmount' => 1000.0, 'ToAmount' => 30000.0, ) ); $campaigns = PaymentPlanCalculator::getMonthlyAmountToPayFromCampaigns($orderTotal, $campaigns, $decimals, $ignoreMinMaxFlag); echo '<pre>' . print_r($campaigns, true) . '</pre>';
输出
Array ( [0] => Array ( [CampaignCode] => 213060 [Description] => Dela upp betalningen på 60 månader [PaymentPlanType] => 0 [ContractLengthInMonths] => 60 [MonthlyAnnuityFactor] => 0.02555 [InitialFee] => 100 [NotificationFee] => 29 [InterestRatePercent] => 16.75 [NumberOfInterestFreeMonths] => 3 [NumberOfPaymentFreeMonths] => 3 [FromAmount] => 1000 [ToAmount] => 50000 [MonthlyAmountToPay] => 317 ) [1] => Array ( [CampaignCode] => 310012 [Description] => Dela upp betalningen på 12 månader (räntefritt) [PaymentPlanType] => 1 [ContractLengthInMonths] => 12 [MonthlyAnnuityFactor] => 0.08333 [InitialFee] => 295 [NotificationFee] => 35 [InterestRatePercent] => 0 [NumberOfInterestFreeMonths] => 12 [NumberOfPaymentFreeMonths] => 0 [FromAmount] => 1000 [ToAmount] => 30000 [MonthlyAmountToPay] => 993 ) )
9.1.7 获取多个活动的实际利率
输入
<?php require_once 'path/to/vendor/autoloader/'; use \Svea\WebPay\Helper\PaymentPlanHelper\PaymentPlanCalculator; $orderTotal = 11200; $decimals = 0; // This parameter is optional and will default to 0, use 2 decimals if payments are in euro $ignoreMinMaxFlag = false; // This parameters is optional and default to false, if set to true it will return all campaigns regardless of if it's valid for the order total $campaigns = array ( 0 => array( 'CampaignCode' => 213060, 'Description' => 'Dela upp betalningen på 60 månader', 'PaymentPlanType' => 0, 'ContractLengthInMonths' => 60, 'MonthlyAnnuityFactor' => 0.02555, 'InitialFee' => 100.0, 'NotificationFee' => 29.0, 'InterestRatePercent' => 16.75, 'NumberOfInterestFreeMonths' => 3, 'NumberOfPaymentFreeMonths' => 3, 'FromAmount' => 1000.0, 'ToAmount' => 50000.0 ), 1 => array ( 'CampaignCode' => 310012, 'Description' => 'Dela upp betalningen på 12 månader (räntefritt)', 'PaymentPlanType' => 1, 'ContractLengthInMonths' => 12, 'MonthlyAnnuityFactor' => 0.08333, 'InitialFee' => 295.0, 'NotificationFee' => 35.0, 'InterestRatePercent' => 0.0, 'NumberOfInterestFreeMonths' => 12, 'NumberOfPaymentFreeMonths' => 0, 'FromAmount' => 1000.0, 'ToAmount' => 30000.0, ) ); $campaigns = PaymentPlanCalculator::getEffectiveInterestRateFromCampaigns($orderTotal, $campaigns, $decimals, $ignoreMinMaxFlag); echo '<pre>' . print_r($campaigns, true) . '</pre>';
输出
Array ( [0] => Array ( [CampaignCode] => 213060 [Description] => Dela upp betalningen på 60 månader [PaymentPlanType] => 0 [ContractLengthInMonths] => 60 [MonthlyAnnuityFactor] => 0.02555 [InitialFee] => 100 [NotificationFee] => 29 [InterestRatePercent] => 16.75 [NumberOfInterestFreeMonths] => 3 [NumberOfPaymentFreeMonths] => 3 [FromAmount] => 1000 [ToAmount] => 50000 [EffectiveInterestRate] => 21.33 ) [1] => Array ( [CampaignCode] => 310012 [Description] => Dela upp betalningen på 12 månader (räntefritt) [PaymentPlanType] => 1 [ContractLengthInMonths] => 12 [MonthlyAnnuityFactor] => 0.08333 [InitialFee] => 295 [NotificationFee] => 35 [InterestRatePercent] => 0 [NumberOfInterestFreeMonths] => 12 [NumberOfPaymentFreeMonths] => 0 [FromAmount] => 1000 [ToAmount] => 30000 [EffectiveInterestRate] => 12.44 ) )
9.1.8 获取多个活动的所有计算结果
输入
<?php require_once 'path/to/vendor/autoloader/'; use \Svea\WebPay\Helper\PaymentPlanHelper\PaymentPlanCalculator; $orderTotal = 11200; $decimals = 0; // This parameter is optional and will default to 0, use 2 decimals if payments are in euro $ignoreMinMaxFlag = false; // This parameters is optional and default to false, if set to true it will return all campaigns regardless of if it's valid for the order total $campaigns = array ( 0 => array( 'CampaignCode' => 213060, 'Description' => 'Dela upp betalningen på 60 månader', 'PaymentPlanType' => 0, 'ContractLengthInMonths' => 60, 'MonthlyAnnuityFactor' => 0.02555, 'InitialFee' => 100.0, 'NotificationFee' => 29.0, 'InterestRatePercent' => 16.75, 'NumberOfInterestFreeMonths' => 3, 'NumberOfPaymentFreeMonths' => 3, 'FromAmount' => 1000.0, 'ToAmount' => 50000.0 ), 1 => array ( 'CampaignCode' => 310012, 'Description' => 'Dela upp betalningen på 12 månader (räntefritt)', 'PaymentPlanType' => 1, 'ContractLengthInMonths' => 12, 'MonthlyAnnuityFactor' => 0.08333, 'InitialFee' => 295.0, 'NotificationFee' => 35.0, 'InterestRatePercent' => 0.0, 'NumberOfInterestFreeMonths' => 12, 'NumberOfPaymentFreeMonths' => 0, 'FromAmount' => 1000.0, 'ToAmount' => 30000.0, ) ); $campaigns = PaymentPlanCalculator::getAllCalculationsFromCampaigns($orderTotal, $campaigns, $decimals, $ignoreMinMaxFlag); echo '<pre>' . print_r($campaigns, true) . '</pre>';
输出
Array ( [0] => Array ( [CampaignCode] => 213060 [Description] => Dela upp betalningen på 60 månader [PaymentPlanType] => 0 [ContractLengthInMonths] => 60 [MonthlyAnnuityFactor] => 0.02555 [InitialFee] => 100 [NotificationFee] => 29 [InterestRatePercent] => 16.75 [NumberOfInterestFreeMonths] => 3 [NumberOfPaymentFreeMonths] => 3 [FromAmount] => 1000 [ToAmount] => 50000 [EffectiveInterestRate] => 21.33 [TotalAmountToPay] => 18067 [MonthlyAmountToPay] => 317 ) [1] => Array ( [CampaignCode] => 310012 [Description] => Dela upp betalningen på 12 månader (räntefritt) [PaymentPlanType] => 1 [ContractLengthInMonths] => 12 [MonthlyAnnuityFactor] => 0.08333 [InitialFee] => 295 [NotificationFee] => 35 [InterestRatePercent] => 0 [NumberOfInterestFreeMonths] => 12 [NumberOfPaymentFreeMonths] => 0 [FromAmount] => 1000 [ToAmount] => 30000 [EffectiveInterestRate] => 12.44 [TotalAmountToPay] => 11915 [MonthlyAmountToPay] => 993 ) )
9.2 Helper::paymentPlanPricePerMonth()
此方法已被标记为弃用,并将在未来从集成包中删除,请使用 PaymentPlanCalculator 代替。
这是一个辅助函数,用于计算给定金额的不同分期付款选项的每月价格。这些信息可用于在结账时显示支付选项,或显示产品级别上每月最低应付款项。
如果ignoreMaxAndMinFlag设置为true,则返回的数组还包含给定金额的理论月供,即使该活动可能实际上不可用于支付请求,如果金额超出实际活动的最小/最大限制。如果标志设置为false或未设置,值数组将不包括此类金额,这可能导致结果中的值数组为空。
<?php ... $paymentPlanParams = WebPay::getPaymentPlanParams($config)->setCountryCode("SE")->doRequest(); $response = Helper::paymentPlanPricePerMonth($amount, $paymentPlanParams, $ignoreMaxAndMinFlag = false); // returns PaymentPlanPricePerMonth $firstCampaign = $response->values[0]['campaignCode']; // i.e. [campaignCode] => 310012 $firstCampaignDescription = $response->values[0]['description']; // i.e. [description] => Dela upp betalningen på 12 månader (räntefritt) $pricePerMonthForFirstCampaign = $response->values[0]['pricePerMonth']; // i.e. [pricePerMonth] => 201.66666666667 ...
9.2.3 getRequestTotals()
如果您在发送请求之前需要知道Svea的订单总额,可以使用getRequestTotals()
方法获取包括增值税、不含增值税的金额和增值税总额。
例如,如果您的集成只处理整数订单金额,您可能需要向订单提供补偿行,以确保Svea系统中的开票订单总额与您的集成订单总额匹配
您的集成有以下订单总额(仅限整数)包含一个商品:1件商品成本1400克朗,包括6%的增值税(即1321克朗不含增值税,您的系统中79克朗为增值税)
订单行使用以下代码指定,然后发送到Svea
<?php $order = WebPay::createOrder($config)-> ->addOrderRow( WebPayItem::orderRow() ->setAmountIncVat(1400.00) ->setVatPercent(6) ->setQuantity(1) ); ... $response = $order->useInvoicePayment->doRequest();
Svea始终将订单重新计算为一个总和和一个增值税百分比,此订单在Svea后台办公室表示为
Price (excl. VAT) Price (incl. VAT) Totalt netto VAT% Sum (incl. VAT)
1320,75 1400.00 1320,75 6.00 1400,00
------- ----- -------
1320,75 79,25 1400,00
如果我们尝试通过添加补偿(即折扣行)来弥补差异
<?php $order->addDiscount( WebPayItem::fixedDiscount() ->setAmountIncVat(-0.25) // a negative discount shows up as a positive adjustment ->setVatPercent(0) ) ...
它将显示为
Price (excl. VAT) Price (incl. VAT) Totalt netto VAT% Sum (incl. VAT)
1320,75 1400.00 1320,75 6.00 1400,00
0,25 0,25 0,25 0.00 0,25
------- ----- -------
1321,00 79,25 1400,25
这不是我们想要的。
正确的方法是使用从不含增值税的商品价格计算的含增值税的总金额发送订单,然后添加一个折扣行,这样商品行的不含增值税金额和增值税金额就正确了,以及向客户收取的总金额
<?php $order = WebPay::createOrder($config) ->addOrderRow( WebPayItem::orderRow() ->setAmountIncVat(1400.26) ->setVatPercent(6) ->setQuantity(1) ) ->addDiscount( WebPayItem::fixedDiscount() ->setAmountIncVat(-0.26) ->setVatPercent(0) ) ...
它将显示为
Price (excl. VAT) Price (incl. VAT) Totalt netto VAT% Sum (incl. VAT)
1321,00 1400,26 1321,00 6.00 1400,26
-0,26 -0,26 -0,26 0.00 -0,26
------- ----- -------
1320,74 79,26 1400,00
这几乎是我们可以达到的精确度。(不幸的是,没有办法只引入增值税折扣,因为您需要支付整个1321克朗的增值税,而不管实际向客户收取的总额是多少。)
getRequestTotal()
对于webservice请求返回了订单行将如何在我们系统中处理的计算总和。返回一个包含total_exvat、total_incvat和total_vat的数组。
9.3 request validateOrder(),prepareRequest(),getRequestTotals()方法
在模块开发或调试期间,各种信息方法可以作为创建订单过程中doRequest()
的最终步骤的替代方法,以获取有关将发送给Svea的实际请求数据的更多信息。
9.3.1 prepareRequest()
prepareRequest()
方法将执行doRequest()
所做的一切,除了将SOAP请求发送到Svea--相反,它返回一个可检查的对象,其中包含将在doRequest调用中发送的数据。prepareRequest的输出也被doRequest方法内部使用。要使用,只需将prepareRequest()
替换为最终的doRequest()
,然后检查返回对象的内容。
9.3.2 validateOrder()
validateOrder()
方法验证订单对象中是否包含所有必需的属性,针对特定的国家/地区和选择的支付方式组合,它返回一个包含任何发现的错误的数组。
9.3.3 getRequestTotals()
如果您在发送请求之前需要知道Svea的订单总额,可以使用getRequestTotals()
方法获取包括增值税、不含增值税的金额和增值税总额。
例如,如果您的集成只处理整数订单金额,您可能需要向订单提供补偿行,以确保Svea系统中的开票订单总额与您的集成订单总额匹配
您的集成有以下订单总额(仅限整数)包含一个商品:1件商品成本1400克朗,包括6%的增值税(即1321克朗不含增值税,您的系统中79克朗为增值税)
订单行使用以下代码指定,然后发送到Svea
<?php $order = WebPay::createOrder($config)-> ->addOrderRow( WebPayItem::orderRow() ->setAmountIncVat(1400.00) ->setVatPercent(6) ->setQuantity(1) ); ... $response = $order->useInvoicePayment->doRequest();
Svea始终将订单重新计算为一个总和和一个增值税百分比,此订单在Svea后台办公室表示为
Price (excl. VAT) Price (incl. VAT) Totalt netto VAT% Sum (incl. VAT)
1320,75 1400.00 1320,75 6.00 1400,00
------- ----- -------
1320,75 79,25 1400,00
如果我们尝试通过添加补偿(即折扣行)来弥补差异
<?php $order->addDiscount( WebPayItem::fixedDiscount() ->setAmountIncVat(-0.25) // a negative discount shows up as a positive adjustment ->setVatPercent(0) ) ...
它将显示为
Price (excl. VAT) Price (incl. VAT) Totalt netto VAT% Sum (incl. VAT)
1320,75 1400.00 1320,75 6.00 1400,00
0,25 0,25 0,25 0.00 0,25
------- ----- -------
1321,00 79,25 1400,25
这不是我们想要的。
正确的方法是使用从不含增值税的商品价格计算的含增值税的总金额发送订单,然后添加一个折扣行,这样商品行的不含增值税金额和增值税金额就正确了,以及向客户收取的总金额
<?php $order = WebPay::createOrder($config) ->addOrderRow( WebPayItem::orderRow() ->setAmountIncVat(1400.26) ->setVatPercent(6) ->setQuantity(1) ) ->addDiscount( WebPayItem::fixedDiscount() ->setAmountIncVat(-0.26) ->setVatPercent(0) ) ...
它将显示为
Price (excl. VAT) Price (incl. VAT) Totalt netto VAT% Sum (incl. VAT)
1321,00 1400,26 1321,00 6.00 1400,26
-0,26 -0,26 -0,26 0.00 -0,26
------- ----- -------
1320,74 79,26 1400,00
这几乎是我们可以达到的精确度。(不幸的是,没有办法只引入增值税折扣,因为您需要支付整个1321克朗的增值税,而不管实际向客户收取的总额是多少。)
getRequestTotal()
对于webservice请求返回了订单行将如何在我们系统中处理的计算总和。返回一个包含total_exvat、total_incvat和total_vat的数组。
9.4 记录原始HTTP请求
您可以通过调用构建请求时的enableLogging方法来获取原始http日志以帮助调试可能发生的问题,要启用日志记录,您只需调用构建请求时的enableLogging方法,如下所示
请求
<?php $svea_order_id = 1048731; $svea_query = WebPayAdmin::queryOrder(ConfigurationService::getTestConfig()) ->setOrderId($svea_order_id) ->setCountryCode('SE') ->enableLogging(true) ->queryAccountCreditOrder() ->doRequest();
日志将在响应中定义。
注意:这仅适用于通过SOAP发送的请求。
9.5 Peppol-ID 验证
您可以通过调用 Helper 函数 isValidPeppolId() 来检查一个字符串是否是有效的 Peppol-ID。
示例
<?php require_once 'vendor/autoload.php'; use Svea\WebPay\Helper\Helper; $var = '1234:abc1234'; if(Helper::isValidPeppolId($var)) { // Valid Peppol-ID } else { // Not Valid Peppol-ID }
10. 常见问题
10.1 支持的货币
问:每种支付方式支持哪些货币?
答:发票和部分付款 对于发票和直接银行付款方式,假设的货币与商户账户(客户 ID)相关联,而每个账户又与一个特定的国家相关联。这就是为什么您作为商户需要在订单中指定国家代码,并必须使用相应货币的金额(即使用 setCountryCode('SE') 设置国家代码的发票订单始终假设为瑞典克朗)。
信用卡和直接银行转账 对于信用卡订单,Svea 在指定订单时接受任何货币。
收单行随后(通过信用卡公司)向最终用户的发行银行(即提供最终用户卡的银行)询问交易是否被接受。如果是这样,则通过 Svea 将此信息传递给商户,这对最终用户来说就是故事的结束。
商户,即您的网店,然后从他们的收单银行收到钱。这通常在夜间完成,当收单银行(通过信用卡公司)收到商户的已确认卡交易列表时,相应地支付给商户。
收单银行支持 关键点是商户必须与他们的收单银行达成协议,以确定他们接受的货币。Svea 没有办法知道这一点,所以商户需要在使用原始请求时提供正确的货币。
tl;dr 对于发票和部分付款,订单金额假设为该国货币。对于信用卡和直接银行转账,我们尊重指定的货币和金额,但您只能指定与您的收单银行达成协议的货币。
10.2 其他支付方式凭证
问:我需要什么凭证才能使用 PayPal 等支付方式通过 PayPage?
答:当您注册 Svea 时,您将获得一个商户 ID,该 ID 用于所有托管支付方式。对于商户 ID,可以启用一个或多个支付方式,例如信用卡、使用各种银行的直接银行付款、PayPal 等。
要启用新的支付方式,您的商户需要根据 Svea 的要求配置各种凭证。请向您的 Svea 集成经理咨询有关需要哪些确切凭证的更多信息。
10.3 我的店铺订单总额与 Svea 系统中的订单总额不匹配
问:我电子商务平台的订单行总和与 Svea 后台办公室和/或发票上的总和不相符?
答:很遗憾,这可能会发生,主要是当使用发票支付方式时,可能由几个不同原因造成,主要原因是您的集成(即商店/电子商务平台)内部表示价格的方式。如果集成(即汇总订单总额的方式、每行或总金额的四舍五入、税前/税后数量应用等)与 Svea 进行发票计算的方式不同,系统之间的订单总额可能不匹配。
如果这种情况发生,您无法调整平台设置以匹配,我们建议您使用 9.2.3 节中描述的 getOrderTotals 函数向订单添加补偿行。
附录
支付方式
用于 usePaymentMethod($paymentMethod) 和 usePayPage()->includePaymentMethods(..., ..., ...) 等。
| Payment method | Description |
|-----------------------------------|-----------------------------------------------|
| PaymentMethod::BANKAXESS | Direct bank payments, Norway |
| PaymentMethod::NORDEA_SE | Direct bank payment, Nordea, Sweden. |
| PaymentMethod::SEB_SE | Direct bank payment, private, SEB, Sweden. |
| PaymentMethod::SEBFTG_SE | Direct bank payment, company, SEB, Sweden. |
| PaymentMethod::SHB_SE | Direct bank payment, Handelsbanken, Sweden. |
| PaymentMethod::SWEDBANK_SE | Direct bank payment, Swedbank, Sweden. |
| PaymentMethod::KORTCERT | Card payments, Certitrade. |
| PaymentMethod::SVEACARDPAY | Card payments, SveaCardPay. |
| PaymentMethod::PAYPAL | Paypal |
| PaymentMethod::SKRILL | Card payment with Dankort, Skrill. |
| PaymentMethod::INVOICE | Invoice by PayPage. |
| PaymentMethod::PAYMENTPLAN | PaymentPlan by PayPage. |
| PaymentMethod::SWISH | Swish, only Sweden |