Libraries are hosted at GitHub.
PHP: https://github.com/PaysonAB/Payson1-PHP
This is a library for Payson 1.0.
Code examples for this library are included in the example folder.
.NET: https://github.com/PaysonAB/Payson1-.NET
The library include a complete demo store to get you started, visit code samples for examples using this library.
SEK – Invoice, Payment plan, Card (Visa, MasterCard), Direct payment by bank, PaysonAccount
EUR – Card (Visa, MasterCard), Direct payment by bank, PaysonAccount
The payment methods displayed will be different depending on the parameters sent in the pay-request. The payment page is responsive and will be optimized for the device used by your customer.
A separate test system is available that can be used to test your integration. It has the same functionality as the live API including IPN, but no real money will be moved. For bank and credit card payments a bank simulation page will be shown in place of the live bank page which allow you to simulate an approved or denied bank response.
Test Agent & Customer
The test system does not share accounts with the live site. A test agent has been setup that can be used in place of the live agent account. The agent is approved for both credit card/bank payments and invoice payments.
Credentials | Value |
---|---|
API User ID (AgentId): | 4 |
API Password (MD5-key): | 2acab30d-fe50-426f-90d7-8c60a7eb31d4 |
Receiver Email: | testagent-checkout2@payson.se |
Important: The test credentials can only be used when initiating a test transaction i.e. when communicating with test-api.payson.se and test-www.payson.se. Any attempt to use these credentials with the production environment will result in failed authentication (ERROR 520003).
For more detailed testing you may create your own test agent for use in the test environment. Create your own test agent here. This test agent will be automatically approved for both credit card/bank payments and invoice payments. Using your own test agent makes it possible for you to login to that TestAccount (on the test enironment) and see the requestlogs for your test agent.
Any credit card with a valid checksum digit and valid prefix will work for test transactions. The card will not be charged.
Any customer email and first/last name will work, but it is also possible to use our predefined test customer.
Method/Action | Test URL |
---|---|
Pay Forward URL | https://test-checkout.payson.se/payment/?token={token} |
Pay Endpoint | https://test-api.payson.se/1.0/Pay/ |
PaymentDetails Endpoint | https://test-api.payson.se/1.0/PaymentDetails/ |
PaymentUpdate Endpoint | https://test-api.payson.se/1.0/PaymentUpdate/ |
Validate Endpoint | https://test-api.payson.se/1.0/Validate/ |
AccountInfo Endpoint | https://test-api.payson.se/1.0/AccountInfo/ |
Limitations of the test environment
There are several limitations and differences in the test environment compared to the live system.
Testing on the live API
It is recommended that you also do some tests in the live API when your integration is complete to verify that everything is setup correctly including the action URLs.
The easiest way to minimize the fees involved for card and bank payments is to refund the payment. The refund function can be reached from the payment history details page in the account.
In the case of invoices no fees and no actual invoices are issued until you mark them as shipped and shipped invoices can be credited.
HTTP Headers
Headers are used to specify API credentials and HTTP content type. The following HTTP Headers can/must be submitted with each request to Payson:
Header | Description | |
---|---|---|
Required | PAYSON-SECURITY-USERID | Your API User ID (AgentId). |
Required | PAYSON-SECURITY-PASSWORD | Your API Password (MD5-key). |
Required | Content-Type | Value must be: application/x-www-form-urlencoded |
Optional | PAYSON-APPLICATION-ID | Your Application ID. (Only applicable if you have received one) |
HTTP Message body
The message body is used to provide parameters needed to complete the requested action. The parameter list must be formatted as a list of Name-Value pairs (NVP formatted) separated by the ampersand (&) sign, i.e. must be in the form ‘NAME_1=VALUE_1&NAME_2=VALUE_2&…&NAME_N=VALUE_N’.
HTTP response
In all cases except for the ‘Validate’ action, the HTTP response message body consists of an NVP-formatted string as described above. Each NVP-formatted string has parameters that describe the overall success of the requested action, as well as possible additional parameters specific to the requested action.
Forward URL
After you have received a token, redirect the customer to the following url to complete the payment:
https://checkout.payson.se/payment/?token={token}
Security
All requests to the Payson API servers are made over HTTPS using 128-bit encryption. The requests are routed through the sub domain api.payson.se, for which SecureTrust CA has signed the certificate.
Your API credentials must be provided in every request to Payson in order to be valid.
Ensure that all API calls are made with TLS 1.1 or higher.
Payment Token
You will receive a payment reference, or ‘payment token’, from an initial pay action. The token will be used in most of subsequent requests to Payson regarding that payment.
Actions are initiated by sending HTTP POST requests to endpoint URIs located at Paysons servers.
Initializes a payment request.
API method: POST
API endpoint: https://api.payson.se/1.0/Pay/
Required | Parameter | Data type | Description |
---|---|---|---|
Required | returnUrl | string (2048) | URL to which the customer’s browser is redirected after the payment is completed.Note: This includes both successful and unsuccessful payments. |
Required | cancelUrl | string (2048) | URL to which the customer is redirected if the payment is manually canceled by the user before it is completed. |
Recommended | ipnNotificationUrl | string (2048) | The URL for receiving an Instant Payment Notification about this payment.Note: This parameter has been made optional due to backward compatability. Read more about the use of it here » |
Required | memo | string (128) | Description of items the customer is purchasing. |
Required | senderEmail | string (128) | Email address of the person sending money. This is the Payson account where the settled amount is transferred from. |
Optional | senderFirstName | string (128) | First name of the buyer as entered during checkout. |
Optional | senderLastName | string (128) | Last name of the buyer as entered during checkout. |
Optional | localeCode | LocaleCode | Locale of pages displayed by Payson during payment. Default: SV |
Optional | currencyCode | CurrencyCode | The currency used for the payment. Default: SEK |
Optional | fundingList.fundingConstraint (0..N).constraint | FundingConstraint | Specifies a list of allowed funding options for the payment. If this field is omitted, the payment can be funded by any funding type that is supported for the merchant (excluding invoice). |
Optional [Deprecated] | invoiceFee | decimal | An invoice fee that will be added as an order item.
|
Optional | custom | string (256) | A free-form field for your own use. This will be returned in requests to the PaymentDetails API endpoint. |
Optional | trackingId | string (128) | Your own tracking id. This will be returned in requests to the PaymentDetails API endpoint. |
Optional [Deprecated] | guaranteeOffered | GuaranteeOffered | Whether Payson Guarantee is offered or not. Default: No |
Optional | showReceiptPage | bool | Whether to show the receipt page in Paysons 1.0. Default: true |
Optional [Deprecated] Receiver Details
The list of receivers. If you have more than one receiver you must specify exactly one as primary. |
|||
Required | receiverList.receiver (0..N).email | string (128) | Email address of the receiver. |
Required | receiverList.receiver (0..N).amount | decimal | The amount (including VAT) to transfer to this recipient.Note: If you have more than one receiver, the primary receiver’s amount must still be the full amount of the payment. |
Optional | receiverList.receiver (0..N).primary | bool | Whether this receiver is the primary receiver. This only applies if there is more than one receiver. |
Order Item Details | |||
Note: Order Items are required for Invoice, and optional for all other payments types. | |||
Required | orderItemList.orderItem (0..N).description | string (128) | Description of this item. |
Required | orderItemList.orderItem (0..N).sku | string (128) | SKU of this item. |
Required | orderItemList.orderItem (0..N).quantity | decimal | Quantity of this item. |
Required | orderItemList.orderItem (0..N).unitPrice | decimal | The unit price of this item not including VAT. Can also be a negative amount for a discount. |
Required | orderItemList.orderItem (0..N).taxPercentage | decimal | Tax percentage for this item. Note: Must be a decimal value and not an actual percentage. E.g. for a 25% tax percentage use 0.25. |
Pay Response Parameters
Parameter | Data type | Description |
---|---|---|
responseEnvelope.ack | AckCode | Acknowledge code indicating the overall success of the request. |
responseEnvelope.timestamp | DateTime | Timestamp that identifies when the response was sent. |
responseEnvelope.correlationId | Not used | |
TOKEN | Guid | A token by which you identify to Payson that you are processing this payment. |
Get details about an existing payment.
API method: POST
API endpoint: https://api.payson.se/1.0/PaymentDetails/
PaymentDetails request parameters
Required | Parameter | Data type | Description |
---|---|---|---|
Required | token | Guid | The token obtained when creating the payment. |
PaymentDetails Response Parameters
Parameter | Data type | Description |
---|---|---|
responseEnvelope.ack | AckCode | Acknowledge code indicating the overall success of the request. |
responseEnvelope.timestamp | DateTime | Timestamp that identifies when the response was sent. |
responseEnvelope.correlationId | Not used | |
purchaseId | int | Payson purchaseId for this payment. |
senderEmail | string | The sender’s email address. |
status | PaymentStatus | The status of the payment. |
type | PaymentType | Type of payment. |
guaranteeStatus | GuaranteeStatus | The status of an ongoing Payson Guarantee payment. This is only set if type is GUARANTEE. |
guaranteeDeadlineTimestamp | DateTime | Timestamp that identifies when the next guarantee deadline is due, if one exists. |
invoiceStatus | InvoiceStatus | The status of an ongoing Payson Invoice payment. This is only set if type is INVOICE. |
custom | string | A free-form field submitted with the Pay request. |
trackingId | string | Your own invoice or tracking id submitted with the Pay request. |
receiverList.receiver(n).email | string | Email address of the receiver. |
receiverList.receiver(n).amount | string | The amount to transfer to this receiver. |
receiverList.receiver(n).primary | bool | Determines whether this is the primary receiver or not. |
currencyCode | CurrencyCode | A three-character currency code. |
receiverFee | decimal | The fee charged the receiver of the payment |
orderItemList.orderItem(n).description | string | Order item description, if set. |
orderItemList.orderItem(n).unitPrice | decimal | Order item unit price, if set. |
orderItemList.orderItem(n).quantity | decimal | Order item quantity, if set. |
orderItemList.orderItem(n).taxPercentage | decimal | Order item tax percentage, if set. |
orderItemList.orderItem(n).sku | string | Order item SKU, if set. |
Shipping address
Shipping address info. Only set if the type is INVOICE and invoiceStatus is one of ORDERCREATED, SHIPPED, DONE or CREDITED. Please note that this address must be used as shipping address.
Parameter | Data type | Description |
---|---|---|
shippingAddress.name | string | The name of the shipment’s receiver. |
shippingAddress.streetAddress | string | The shipment receiver’s street address. |
shippingAddress.postalCode | string | The shipment receiver’s postal code. |
shippingAddress.city | string | The shipment receiver’s city. |
shippingAddress.country | string | The shipment receiver’s country. |
Update an existing payment, for instance mark an order as shipped or canceled. The following updating actions are available:
API method: POST
API endpoint: https://api.payson.se/1.0/PaymentUpdate/
PaymentUpdate request parameters
Required | Parameter | Data type | Description |
---|---|---|---|
Required | token | Guid | The token obtained when creating the payment. |
Required | action | UpdateAction | Action to take for this payment. |
PaymentUpdate Response Parameters
Parameter | Data type | Description |
---|---|---|
responseEnvelope.ack | AckCode | Acknowledge code indicating the overall success of the request. |
responseEnvelope.timestamp | DateTime | Timestamp that identifies when the response was sent. |
responseEnvelope.correlationId | Not used |
This method is used to validate the content of the IPN message that was sent to your ipnNotificationUrl.
API method: POST
API endpoint: https://api.payson.se/1.0/Validate/
Validate request parameters
Send the complete unaltered IPN message back to Payson; the message must contain the same parameters in the same order and be encoded in the same way as the original message.
Validate Response Parameters
A single-word message (Note: NOT an NVP message) is returned. One of the following values is used as content:
Important:
After you receive the VERIFIED message, there are other important checks you should perform. For instance, confirm that the payment status is COMPLETED for bank and card payments and Payson Guarantee payments. For invoice payment, make sure the invoiceStatus is ORDERCREATED. You should also verify that the payment has not already been processed in your system.
It is also a good idea to validate that the receiver’s email address is registered to you and that the price, item description, and so on match the transaction on your website.
This method is used to validate API credentials and get basic information about API account.
API method: POST
API endpoint: https://api.payson.se/1.0/AccountInfo/
AccountInfo request parameters
No additional parameters should be sent.
For some curl requests it might be necessary to set ‘Content-Length: 0’ in header.
AccountInfo Response Parameters
Parameter | Data type | Description |
---|---|---|
responseEnvelope.ack | AckCode | Acknowledge code indicating the overall success of the request. |
responseEnvelope.timestamp | DateTime | Timestamp that identifies when the response was sent. |
responseEnvelope.correlationId | Not used | |
accountEmail | string | Payson account email attached to request agent. |
status | string | Approved or Denied. |
merchantId | int | Agent Id. |
enabledForInvoice | bool | Is agent enabled to receive invoice payments |
enabledForpaymentPlan | bool | Is agent enabled to receive payment plan payments |
Decimal
For all decimals used, the decimal separator must be a period (.)
Guid
A 38 characters long globally unique identifier.
GuaranteeOffered
Must be one of the following values:
FundingConstraint
Must each be one of the following values:
CurrencyCode
Must be one of the following values:
LocaleCode
Must be one of the following values:
AckCode
PaymentType
PaymentStatus
Note: for invoice and Guarantee payments the corresponding statuses (InvoiceStatus and GuaranteeStatus) should be used.
[Deprecated] GuaranteeStatus
InvoiceStatus
It can be one of the following values:
UpdateAction
Must be one of the following values:
Error Response Parameters
This section details the possible errors you can receive in a request to a Payson API server.
Parameter | Description |
---|---|
errorList.error(n).errorId | A number that uniquely identifies an error. |
errorList.error(n).message | A description of errorId. |
errorList.error(n).parameter | Indicates which submitted parameter caused the error. Only included where appropriate. |
Code | Message |
---|---|
500000 | System error. |
520002 | Internal error. |
520003 | Authentication failed; Credentials were not valid. |
520005 | The merchant account is locked. |
539041 | An email account is not receive enabled. |
579008 | Number of primary receivers exceeds 1. |
579009 | If PaysonGuarantee is offered, there may be at most one receiver |
580021 | Invalid parameter – too long. |
580022 | Your request was invalid. Check the parameter of the error to see which is invalid. |
580028 | A URL supplied with the request is malformed. |
580029 | A required parameter was not provided. Check the error parameter list. |
580030 | The amount is below the minimum limit. |
580031 | The amount is above the maximum limit. |
589018 | Invalid payment token |
589053 | All payment methods have been disabled for this combination of funding constraint, merchant and receiver. |
590001 | The total amount specified for receivers does not match the total amount specified by the order items. |
590005 | Not all related order item parameters where specified. All or none of unitPrice, quantity, taxPercentage and sku must be set. |
590006 | Invoice requires one receiver. |
590008 | Invoice requires that order items are specified. |
590009 | Invoice payments are not available to this merchant. |
590010 | The requested action is not possible in the current state of the payment. |
590011 | The amount on the invoice is below the minimum limit. |
590012 | Invoice does not support the selected currency. |
590013 | The invoice fee out of the valid range. |
590015 | The receiver is not allowed to receive invoices. |
590016 | The sender and receiver is the same user. |
590018 | The requested action is not possible for the current type of payment. |
590020 | A primary receiver is required for this kind of payment. |
IPN is a message service that notifies you of events related to Payson payments as they happen. You can use it to automate back-office and administrative functions, such as fulfilling orders, tracking customers, or providing information related to a payment.
ipnNotificationUrl Callback
An IPN message is sent to the URL specified in the ipnNotificationUrl field of the Pay request when the payment changes its state.
An IPN message consists of the same NVP formatted content as a request to PaymentDetails will give and a hash parameter. It will not include the response envelope parameters.
Restrictions
Must use port 80 or 443 (the standard http and https ports)
The IPN protocol consists of three steps:
After successfully completing the protocol, your back-office or administrative process can use the contents of the IPN message and respond appropriately. For example, the IPN message may trigger your system to print shipping labels for items whose payments have cleared, investigate disputes and chargebacks, store information in an accounting system and so on.
Payson can only make requests to the standard ports, meaning port 80 for http and 443 for https requests. If you specify another port the IPN call will fail.
Important: Please note that your ipnNotificationUrl may be called more than once from the Payson service for a given payment. Also note that IPN messages are sent for all status changes, even when a payment fails.
You must validate the IPN content and verify the payment status before marking the payment as done in your system.
Simple Integration
The quickest way to send a customer to the payment page is by posting a form to https://www.payson.se/merchant/default.aspx. Payson will wrap your request and redirect the customer.There are several limitation to this way of calling our API.
Please note that you must send the form by “POST”, not by “GET”. The form should be ISO-8859-1 encoded.
Form request parameters
Required | Parameter | Data type | Description |
---|---|---|---|
Optional | RefNr | string (50) | Your reference to the order. The RefNr is returned to the OkURL. |
Required | OkURL | string (255), html encoded | Url called when a payment is completed. The “return to shop” button will redirect the customer to OkURL. |
Recommended | CancelURL | string (255), html encoded | URL called when a payment failed or if the customer cancels the payment. |
Required | AgentId | int | The unique id provided by Payson when you have been approved as a merchant |
Required | MD5 | string (128) | The MD5 needs to be calculated with your secret MD5 key prior to sending the request to Payson. The calculation is described below. |
Required | GuaranteeOffered | int | Set to 1 if you do not want to offer PaysonGaranti and 2 to offer PaysonGaranti. |
Optional | CustomReceipt | string(5) | False if you want to use Payson’s receipt page. Please note that if you set CustomReceipt to True the customer will be sent to the OkURL immediately after the payment. |
Optional | PaymentMethod | string(20) | 0 (zero) = Show all payment options (Card, internet bank, Payson) 1 = Card (VISA/MasterCard) 2 = Internet bank (SEB, Handelsbanken, Nordea, Danske bank and Swedbank) All available payment options will be shown if left empty. |
Optional | LocaleCode | string(2) | Language used in the checkout window. SV = swedish EN = english FI = finnish Swedish will be the language used if left empty. |
Receiver Details
Required | Parameter | Data type | Description |
---|---|---|---|
Required | SellerEmail | string (50) | Email address of the receiver. |
Buyer Details
Required | Parameter | Data type | Description |
---|---|---|---|
Optional | BuyerEmail | string(128) | The buyer’s email address. |
Optional | BuyerFirstName | string(70) | The buyer’s first name. |
Optional | BuyerLastName | string(70) | The buyer’s last name. |
Product information
Required | Parameter | Data type | Description |
---|---|---|---|
Required | Description | string(200) | A description of the product or service bought. The description is shown in the confirmation email and in the Payson account. |
Required | Cost | decimal | The price of the product or service. Must be more than 10 SEK or 1 EUR. |
Required | ExtraCost | decimal | Used for additional charges such as shipping. |
Optional | CurrencyCode | CurrencyCode | The currency of the payment, SEK or EUR Default: SEK |
Calculating the MD5 hash
To confirm that a call to Payson has been made by the expected shop and that nothing has been added you need to calculate a MD5 hash.
String text = SellerEmail + “:” + Cost + “:” + ExtraCost + “:” + OkURL + “:” + GuaranteeOffered + Key
String Generated_MD5_Hash_Value = MD5(text)
Response to OkURL and CancelURL
If the payment is successful Payson makes up to two requests to OkURL; one from the servers and one if the user is redirected back to the shop by the CustomReceipt parameter or by pressing the “Return to shop” button. If the transaction was canceled or the payment failed a call will instead be made to CancelUrl.
The response will include:
Validating response
Always validate the response to make sure that the call comes from Payson. The OkURL needs to be url decoded and html encoded before the calculation (automatic in $_REQUEST below)
$strYourSecretKey = "?????????"; $strOkURL = $_REQUEST["OkURL"]; $strPaysonRef = $_REQUEST["Paysonref"]; $strTestMD5String = htmlspecialchars( $strOkURL . $strPaysonRef ). $strYourSecretKey; $strMD5Hash = md5($strTestMD5String); if($strMD5Hash == $_REQUEST["MD5"]){ //Correct call from Payson echo "Rätt MD5-summa"; } else { //Incorrect call, not from Payson echo "Felaktig MD5-summa"; }
Example Code
Functions for calculating the MD5 hash and examples in asp, asp .net and php may be found on Agentintegration.zip.
All required parameters must be included when sending the form to Payson, see example below. Note that there is no test server for simple integration. In order to test that your integration works, you must conduct a real payment and then credit the transaction. Remember that the smallest possible transaction amount is 10 SEK.
<form action="https://www.payson.se/merchant/default.aspx" method="post"> <input type="hidden" name="BuyerEmail" value="buyer@mymail.com"> <input type="hidden" name="SellerEmail" value="seller@mymail.com"> <input type="hidden" name="Description" value="En fin grej."> <input type="hidden" name="Cost" value="100"> <input type="hidden" name="ExtraCost" value="5,20"> <input type="hidden" name="OkURL" value="http://www.myokurl.com"> <input type="hidden" name="AgentId" value="000000"> <input type="hidden" name="GuaranteeOffered" value="0"> <input type="hidden" name="MD5" value="Generated_MD5_Hash_Value"> <input type="submit" value="Betala med Payson"> </form>
Testing
To validate your parameters, use https://account.payson.se/Utils/TestSimpleIntegrationParams instead of the production endpoint(https://www.payson.se/merchant/default.aspx ).