PHPackages                             sveaekonomi/webpay - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. sveaekonomi/webpay

ActiveLibrary[Payment Processing](/categories/payments)

sveaekonomi/webpay
==================

Php integration library for Svea payment methods

3.16.1(10mo ago)17111.9k↓21.3%19[4 PRs](https://github.com/sveawebpay/php-integration/pulls)4Apache-2.0PHPPHP &gt;=5.3.0CI failing

Since Nov 2Pushed 10mo ago10 watchersCompare

[ Source](https://github.com/sveawebpay/php-integration)[ Packagist](https://packagist.org/packages/sveaekonomi/webpay)[ RSS](/packages/sveaekonomi-webpay/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (38)Used By (4)

Svea PHP Integration Package Documentation
==========================================

[](#svea-php-integration-package-documentation)

Index
---------------------------------------

[](#index-)

- [I. Introduction](#i-introduction)
- [1. Installing and configuration](#i1)

    - [1.1 Requirements](#i1-1)
    - [1.2 Installation](#i1-2)
    - [1.3 Configuration](#i1-3)
    - [1.4 Using your account credentials with the package](#i1-4)
    - [1.5 Additional integration properties configuration](#i1-5)
- [2. "Hello World"](#i2)
- [3. Building an order](#i3)

    - [3.1 Order builder](#i3-1)
    - [3.2 Order row items](#i3-2)
    - [3.3 Customer identity](#i3-3)
    - [3.4 Additional order attributes](#i3-4)
    - [3.5 Payment method selection](#i3-5)
    - [3.6 Recommended payment method usage](#i3-6)
- [4. Payment method reference](#i4)

    - [4.1 Svea Invoice payment](#i4-1)
    - [4.2 Svea Payment plan payment](#i4-2)
    - [4.3 Card payment](#i4-3)
    - [4.4 Direct bank payment](#i4-4)
    - [4.5 Using the Svea PayPage](#i4-5)
    - [4.6 Svea Checkout](#i4-6)
    - [4.7 Account Credit](#i4-7)
    - [4.8 Swish](#i4-8)
    - [4.9 Examples](#i4-9)
- [5. WebPayItem reference](#i5)

    - [5.1 Specifying item price](#i5-1)
    - [5.2 WebPayItem::orderRow()](#i5-2)
    - [5.3 WebPayItem::shippingFee()](#i5-3)
    - [5.4 WebPayItem::invoiceFee()](#i5-4)
    - [5.5 WebPayItem::fixedDiscount()](#i5-5)
    - [5.6 WebPayItem::relativeDiscount](#i5-6)
    - [5.7 WebPayItem::individualCustomer()](#i5-7)
    - [5.8 WebPayItem::companyCustomer()](#i5-8)
    - [5.9 WebPayItem::numberedOrderRow()](#i5-9)
- [6. WebPay entrypoint method reference](#i6)

    - [6.1 WebPay::createOrder()](#i6-1)
    - [6.2 WebPay::deliverOrder()](#i6-2)
    - [6.3 WebPay::getAddresses()](#i6-3)
    - [6.4 WebPay::getPaymentPlanParams()](#i6-4)
    - [6.5 WebPay::paymentPlanPricePerMonth()](#i6-5)
    - [6.6 WebPay::listPaymentMethods()](#i6-6)
    - [6.7 WebPay::getAccountCreditParams()](#i6-7)
    - [6.8 WebPay::checkout()](#i6-8)
- [7. WebPayAdmin entrypoint method reference](#i7)

    - [7.1 WebPayAdmin::queryTaskInfo()](#i7-1)
    - [7.2 WebPayAdmin::cancelOrder()](#i7-2)
    - [7.3 WebPayAdmin::queryOrder()](#i7-3)
    - [7.4 WebPayAdmin::cancelOrderRows()](#i7-4)
    - [7.5 WebPayAdmin::creditOrderRows()](#i7-5)
    - [7.6 WebPayAdmin::addOrderRows()](#i7-6)
    - [7.7 WebPayAdmin::updateOrderRows()](#i7-7)
    - [7.8 WebPayAdmin::deliverOrderRows()](#i7-8)
    - [7.9 WebPayAdmin::updateOrder()](#i7-9)
    - [7.10 WebPayAdmin::creditAmount()](#i7-10)
    - [7.11 WebPayAdmin::creditOrderRows()](#i7-11)
    - [7.12 WebPayAdmin::cancelRecurSubscription()](#i7-12)
- [8. SveaResponse and response classes](#i8)

    - [8.1. Parsing an asynchronous service response](#i8-1)
    - [8.2. Response accepted and result code](#i8-2)
- [9. Helper Class and Additional Developer Resources and Notes](#i9)

    - [9.1 PaymentPlanCalculator](#i9-1)
    - [9.2 Helper::paymentPlanPricePerMonth()](#i9-2)
    - [9.3 Request validateOrder(), prepareRequest(), getRequestTotals() methods](#i9-3)
    - [9.4 Logging Raw HTTP Requests](#i9-4)
    - [9.5 Peppol-ID validation](#i9-5)
- [10. Frequently Asked Questions](#i10)

    - [10.1 Supported currencies](#i10-1)
    - [10.2 Other payment method credentials](#i10-2)
    - [10.3 My store order totals does not match the order totals in Svea's systems](#i10-3)
- [APPENDIX](#appendix)

I. Introduction
---------------

[](#i-introduction)

#### Short note on Svea Checkout

[](#short-note-on-svea-checkout)

If you want a lightweight integration package that only includes the checkout, you can use the [php-checkout](https://github.com/sveawebpay/php-checkout/) integration package instead.

Read more about how to integrate Svea Checkout in the section [6.7 WebPay::checkout()](#i6-7) and if you wish to see more detailed data structures, see this [documentation](https://checkoutapi.svea.com/docs/html/reference/web-api/data-types/index.htm).

### Svea API

[](#svea-api)

The WebPay class contains the methods required to create orders and perform payment requests. It contains methods to define order contents, send order requests, as well as support methods.

The WebPayAdmin class methods are used to administrate orders after they have been accepted by Svea. It includes methods that update, deliver, cancel and credit orders et.al. and can administrate all types of orders.

### Package design philosophy

[](#package-design-philosophy)

In general, a request using the Svea API starts out with you creating an instance of an order builder class, which is then built up with data using fluent method calls. At a certain point, a method is used to select which service the request will go against. This method then returns an instance of a service request class which handles the specifics of building the request, which in turn returns an instance of the corresponding service response class for inspection.

The WebPay API consists of the entrypoint methods in the WebPay and WebPayAdmin classes. These instantiate builder classes in the Svea namespace. Given i.e. an order builder instance, you then use method calls to populate it with order rows and customer identifiction data. You then choose the payment method and get a request class in return. You then send the request and get a service response from Svea in return. In general, the request classes will validate that all required builder class attributes are present, and if not will throw an exception stating what methods are missing for the request in question.

### Synchronous and asynchronous requests

[](#synchronous-and-asynchronous-requests)

Most service requests are synchronous and return a response immediately. For asynchronous hosted service payment requests, the customer will be redirected to i.e. the selected card payment provider or bank, and you will get a callback to a return url, where where you receive and parse the response.

### Namespaces

[](#namespaces)

The package makes use of PHP namespaces, grouping most classes under the namespace Svea. The entrypoint classes WebPay, WebPayAdmin and associated support classes are excluded from the Svea namespace. The underlying internal services and methods are contained in the Svea sub-namespaces WebService, HostedService and AdminService.

### Fluent API

[](#fluent-api)

The package is built as a fluent API so you can use method chaining when utilising the WebPay and WebPayAdmin entrypoint classes. Available methods should show up in the IDE along with their associated DocBlock, including information on which methods are required for the various payment methods. We recommend making sure that your IDE code completion is enabled to make full use of this feature.

[Back to top](#index)

1. Installing and configuration
--------------------------------------------------------------

[](#1-installing-and-configuration-)

### 1.1 Requirements

[](#11-requirements-)

This integration package has the following requirements:

- PHP 5.3 or higher (5.6+ recommended)
- [Composer](https://getcomposer.org/download/)
- SOAP needs to be enabled on your Web server

### 1.2 Installation

[](#12-installation-)

First of run the following command in your command-line interface:

```
composer require sveaekonomi/webpay

```

Doing this will pull the library into your project and store it in the `vendor` folder with the name `sveaekonomi`.

When you are working with files that will use the library you need to include `vendor/autoload.php`

### 1.3 Configuration

[](#13-configuration-)

In order to use Svea's services you need to authenticate yourself using the credentials provided by Svea. If you're just going to use the stage environment, you can use the credentials that is provided within the integration package.

For the Invoice, Payment Plan and Account credit payment methods, the credentials consist of a set of Username, Password and Client number (one set for each country and service type).

For Card and Direct Bank payments and also for using the Checkout, the credentials consist of a (single) set of a Merchant ID and Secret Word.

### 1.4 Using your account credentials with the package

[](#14-using-your-account-credentials-with-the-package-)

The WebPay and WebPayAdmin entrypoint methods all require a config object when called. The easiest way to get such an object is to use the ConfigurationService::getDefaultConfig() method. Per default, it returns a config object with the Svea test account credentials as used by the integration package test suite.

In order to use your own account credentials, either edit the config\_test.php or config\_prod.php file (depending on the desired environment) with your actual account credentials, or implement the ConfigurationProvider interface in a class of your own -- your implementation could for instance fetch the needed credentials from a database in place of the config files.

### 1.5 Additional integration properties configuration

[](#15-additional-integration-properties-configuration-)

You should also add information about your integration platform (i.e. Magento, OpenCart, or MyAwesomeECommerceSystem etc.), platform version and providing company. See ConfigurationProvider getIntegrationPlatform(), getIntegrationVersion() and getIntegrationCompany() methods, or add that information into the config files.

When configured, the integration properties information will be passed to Svea alongside the various service requests.

See the provided example of how to customize the config files in the [example/config\_getaddresses/](example/config_getaddresses/) folder.

See the [ConfigurationProvider](src/Config/ConfigurationProvider.php) interface and the provided [example of config file](src/Config/config_test.php) for more information.

[Back to top](#index)

2. "Hello World"
-----------------------------------------------

[](#2-hello-world-)

An example of the WebPay API workflow is the following invoice payment, where we wish to perform an invoice order. Let's assume that we have already collected all the needed order data, and will now build an order containing the ordered items (with price, article number info, et al) and customer information (name, address, et al), select a payment method, and send the payment request to Svea.

### 2.1 A complete invoice order

[](#21-a-complete-invoice-order-)

The following is a complete example of how to place an order using the invoice payment method:

```
