NAV
python php

Introduction

To start using API you need to sign up or login with your existing account. Your API credentials can be found in your Swipe profile.

Swipe API is based on REST approach and uses JSON data exchange format. Security is enforced by HMAC-based authentication.

Swipe API is available for both verified and non-verified merchants. You can use Swipe invoices and subscriptions even if your merchant’s account is not verified. You will still have to verify your account to accept payments. As non-verified merchant you can also run payments API in the test mode during the integration process.

Once you have passed the verification your clients will be able to pay for Swipe invoices with just two clicks. As well as, automated payments become available for subscriptions.

To assist you with API integration Swipe offers test mode. To switch between test and live modes use different API credentials that can be found in your Swipe profile.

Authentication

<?php
$public_key = '<public key>';
$private_key = '<private key>';
$reference_id = (string)time();

$authorization_message = $timestamp.' GET /api/v0.5/payments/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'GET',
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/payments/ ', false, $context);
var_dump($result);
?>
import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/payments/'
request_method = 'GET'

data = {
    'client': {'email': 'test@example.com'},
    'amount': 2.75
}
request_body = json.dumps(data)

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = getattr(requests, request_method.lower())(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization},
    data = request_body
)

All API requests are signed with authentication tokens generated by HMAC-SHA256 algorithm. The principles behind it can be found in RFC 2104 and on Wikipedia page.

To authentify you need merchant’s Public and Private API keys. You can find them in your Swipe profile.

The authentication algorithm is implemented as follows:

  1. Current Unix timestamp is saved in a variable. Timestamp shouldn’t be more than 5 minutes behind or 1 minute ahead the current exact time. If the timestamp doesn’t match these terms the request will be declined.

  2. Generate a string that consists of: timestamp created on the first step, request method in uppercase, request URN and URL encoded request body. All parameters are concatenated using spaces and have to be in the exact order as mentioned.

    Structure example: timestamp method URN body

    Example: 1423465200 POST /api/v0.5/payments/ {"email":"hello@swipe.lv"}

    If the request body is empty (as for GET requests), generated string should still end with a trailing space.

    GET request example: 1423465200 GET /api/v0.5/payments/

  3. HMAC algorithm is performed using merchant’s Private API key as an encryption key, string from the second step and SHA-256 hashing algorithm.

  4. Finally, add the Authorization header to the request. Its value consists of comma-separated Public API key, a timestamp generated earlier and HMAC signature created during the third step.

    Authorization header example: public_key , timestamp , 64_symbol_HMAC_signature

Pagination

https://swipe.lv/api/v0.5/<resource>/?limit=7&after_id=34&before_id=25

In Swipe API all requests that fetch object list support pagination. You can set the limit of objects per page and the object to use as the lower or upper fetching boundary.

Example: ?limit=50&after_id=77

Parameter Description
ATTRIBUTES
limit Integer Number of objects per page, from 1 to 100 (100 by default).
after_id Integer ID of an object to fetch a page after (newest first).
before_id Integer ID of an object to fetch a page before (newest first).

Events

You can be notified when certain events happen in Swipe. Just create a webhook for the event and Swipe will let you know when it triggers.

Parameter Description
EVENTS
payment.created payment event Payment created.
payment.paid payment event Payment successfully paid.
payment.failed payment event Payment failed.
invoice.expired invoice event Invoice expired.
transfer.withdrawn transfer event Transfer withdrawn.

Errors

Swipe API error reporting also conforms to REST guidelines. Various HTTP response statuses codes are used to indicate specific types of errors. Most of them are in 4xx client error range; 5xx server error responses are unlikely to encounter but also possible.

Parameter Description
ATTRIBUTES
code Integer HTTP error code.
message Array Error description.

Full page

https://swipe.lv/client/payment/<hash>/full_page/

By default, all payments open in a full page view designed to use all the available viewport space. To use this view, redirect your client’s browser to the full_page_checkout address you receive upon creating the payment. Swipe will manage the payment process from this point. Afterwards, Swipe will navigate your client’s browser back to your website using the redirect URL you have configured.

Preview full page checkout.

iframe

https://swipe.lv/client/payment/<hash>/iframe/

Code example:

<iframe src="https://swipe.lv/client/payment/<hash>/iframe/"></iframe>

If you want to integrate Swipe into your website seamlessly, you can take the advantage of our embed payment form. It will enable your customers to pay without navigating away from your website. To use it, open the iframe_checkout URL you receive in the response to Create Payment request in an iframe element placed in an appropriate spot on your checkout page.

Preview iframe checkout.

Pay button

https://swipe.lv/client/payment/<hash>/button/

Code example:

<a href="https://swipe.lv/en/i/04Fmi9a357b26" title="Pay Now" target="_blank"><img src="https://swipe.lv/static/images/get_link/pay_now_en.png" width="240" height="40" alt="Pay Now"></a>

If you have your own invoice delivery system, you can always power up your invoices with instant payments adding Swipe Pay button to them. With Pay button your invoices can be paid in 2 clicks. To get it done you have to create a payment object first and use its ‘hash’ to generate Pay button.

Preview pay button.

Direct Post

If you would like to customize the payment flow and/or design the payment form yourself, Direct Post (also known as Silent Post) will help.

With this checkout method, your clients enter their card data into a payment form located on your website (no redirects of iframe embedding needed). This <form> element with method="POST" has the action attribute set to the value we provide you with upon creating the payment in Swipe API.

Once the client enters his card credentials, he submits the form and posts his data to our system. From there, we take care of his navigation, making sure he passes 3D Secure checks and redirecting him back to success_redirect or failure_redirect once his payment is complete.

In detail, the process is as follows:

  1. Create a Payment in Swipe API. Provide success_redirect and failure_redirect values in request data. Save the id of the created payment. You will also need the direct_post link provided in the response on the next step.

  2. Create a card data entry <form> element (method="POST" action="<direct_post value from the first step>") on your website. Aside from a method to trigger the native DOM submit event (e.g. <input type="submit">), it should contain the following input fields (field name-s are listed in the first column):

    Name Description
    FIELDS
    cardholder_name Up to 40 symbols.
    number 13-19 symbols with no spaces.
    exp_month A number in the [1..12] range.
    exp_year A number in the [16..99] range.
    cvc 3 digits of CVC2/CVV2 code.

  3. Once client enters his data and submits the form, Swipe processes the payment. Afterwards, client is redirected back to your website using success_redirect or failure_redirect links. payment.paid or payment.failed event is emitted as well, and if you have created webhooks for them Swipe will also perform a server-to-server callback to your system.
    Once either client navigation to your website happens or you receive the webhook callback, mark the corresponding payment as complete in your system.
    Be sure, though, not to rely on the webhook or (especially so) on client navigation alone, lest your checkout will be vulnerable to brute force attacks/fake requests. Recheck status of this payment in Swipe (you will need the id you saved on the first step) and make sure the status field is either paid or withdrawn. You can be sure that payment is complete then.

To sum up, the only big difference from Full Page/iframe integration options mentioned above is step 2: card data entry happens on your website, not in Swipe checkout.

Direct Post allows you to keep the card data entry form on your website, where you are able to fine-tune the checkout process for your needs at all times, while removing the need to comply with full set of PCI DSS SAQ level D requirements; you are able to comply with simpler A-EP instead.

Card saving

Your customers can save their card data to accelerate future payments. To enable this functionality, please:

  1. Create the Client object for your customer first.

  2. Next, create Payment as usual, specifying client_id of a client object just generated.

  3. Finally, redirect your customer to the Full page payment view.

Your customer will have an option to remember their card in the payment form. If a client has saved their card, an indicator next to their name in Clients view will display that. In this case, each of the following invoices/payments you issue with this client_id will be paid instantly by your client once they open the payment form, until they choose to opt out of storing their card data.

Payments

GET https://swipe.lv/client/payment/<hash>/

Payments are available only for verified merchants.

Payment object allows you to accept card payments for your products and services online. It’s an interface for charges and received fund management. Payments can be created in merchant’s profile, via Swipe API or using various solutions for e-commerce engines. To execute test payments during the integration process you can use a test API keys set.

Events: payment.paid, payment.failed

Parameter Description
ATTRIBUTES
id Integer, read-only Payment unique identifier.
hash Sting, read-only Unique token for payment link.
client integer or dictionary ID of the client object or other client details (email, phone, etc.). If the client is new, Swipe will automatically create the object.
products Dictionary An array of product object IDs describing goods and quantities this invoice is for.
subtotal Decimal Sum of the the all invoice product totals. Calculated automatically if not specified.
total Decimal Indicates the amount of money to charge your client for. Not less than zero, minimal amount is 0.30, up to 2 decimal digits.
discount_percent Integer The percentage of subtotal to discount the invoice for.
discount_amount Decimal An amount to discount the invoice total for. Not less than zero and not more than the invoice subtotal.
vat_rate Decimal VAT percentage for the invoice. Not more than two digits after decimal point.
vat_amount Decimal Exact amount of VAT for the invoice. Generated automatically using vat_rate, if not specified.
fee Decimal, read-only Fee paid for this transaction.
fee_details Array, read-only Detailed breakdown of fee paid for this transaction.
fee_type String Responsible side will cover the transaction fee. If not specified, option set in merchant’s profile settings will be used as default.

Possible values: merchant or client.

deposit Decimal, read-only Amount of the payment insurance deposit, if it’s applied. Learn more in transfers.
number String Payment unique reference number. Generated automatically, if not specified.
comment String Up to 125 ASCII symbols.
refund_terms String Merchant’s current refund terms.
custom_invoice_link String Specify link to the invoice webpage or PDF file.
request_info Array Merchant can request the client to specify particular details before making the payment. This information will be saved to the client object. Possible values: first_name, last_name, personal_code, company_name, legal_name, registration_nr, vat_payer_nr, address, iban, swift.
notes String Additional information on invoice for the client up to 10000 symbols.
language String Two-letter language code to set payment interface language. If not specified, option set in merchant’s profile settings will be used as default.

Possible values: en, lv, lt, ru.

date DateTime, read-only Date the payment was made.
status Integer, read-only Additional status is received. Client can notify the merchant that he has made the payment via means other than Swipe.

Possible payment statuses: created, viewed, hold, canceled, paid, withdrawn, chargeback, refunded.

referrer String There are various referrers depending on the platform the payment was created on. Possible referrer values: profile, api, opencart, etc.
success_redirect String You can set custom link for success redirect. If not specified, option set in API keys set settings will be used as default.
failure_redirect String You can set custom link for failure redirect. If not specified, option set in API keys set settings will be used as default.
invoice_id Integer, read-only Invoice attached to the payment, if there is one.
transfer_id Decimal, read-only ID of the transfer payment is attached to. Once the payment is made it’s included in the upcoming transfer. If the payment isn’t made yet, the response will be empty.
due_date String The date payment is valid through in ISO 8601 format. If not specified set to 1 day by default.
timeout_seconds Integer If specificed and greater than zero, your client will only have so many seconds to perform the payment, starting from the moment he opens the payment form. If it is specified it should be either 0 (timeout disabled, the default) or between 60 and 600 seconds (1 and 10 minutes, respectively).
deposit_transfer_id Decimal, read-only ID of the transfer payment deposit is attached to. Once the insurance term is over payment deposit is included in the upcoming transfer. If insurance deposit isn’t applied to the merchant, the response will be empty.
skip_capture boolean Skip immediate execution of this payment. Funds will be reserved for future payment execution or cancellation, see Execute a payment and Cancel a payment requests. Client will see the payment status as “hold” his bank statement during the reservation. Maximum reservation period depends on cardholder’s bank but usually is around one month.
is_test boolean, read-only Set “true” if merchant used test API keys set to create this payment.

Create a payment

POST https://swipe.lv/api/v0.5/payments/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/payments/'
request_method = 'POST'

data = {
    'client': {'email': 'test@example.com'},
    'products': [
        {
            'description': 'Green tea XL pack', 
            'price': 28.50, 
            'quantity': 5
        },
        {
            'description': 'Black tea M pack', 
            'price': 12.35, 
            'quantity': 2
        }
    ],
}
request_body = json.dumps(data)

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = getattr(requests, request_method.lower())(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization},
    data = request_body
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$params = json_encode(array(    
    'client' => array('email' => 'test@example.com'), 
    'products' => array(
            array(
                'description' => 'Green tea XL pack', 
                'price' => 28.50, 
                'quantity' => 5
            ), 
            array(
                'description' => 'Black tea M pack', 
                'price' => 12.35, 
                'quantity' => 2
            ))
        )
    ));

$authorization_message = $timestamp.' POST /api/v0.5/payments/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'POST',
        'content' => $params,
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/payments/ ', false, $context);
var_dump($result);
?>

Response example:

{
  "id": 150, 
  "full_page_checkout": "https://swipe.lv/client/payment/979ffe8e8e74dfcce30c517aca07a5f848ddf8bf2e079080f8b623a2e59afdd8/full_page/", 
  "iframe_checkout": "https://swipe.lv/client/payment/979ffe8e8e74dfcce30c517aca07a5f848ddf8bf2e079080f8b623a2e59afdd8/iframe/", 
  "errors": [], 
  "timestamp": 1447668000
}

You create a payment object to charge a bank card. If merchant uses test API keys set to create a payment specified bank card won’t actually be charged, though everything else will occur as if in live mode.

Events: payment.created

Parameter Description
ATTRIBUTES
client Required ID of the client object or other client details (email, phone, etc.). If the client is new, Swipe will automatically create the object.
products Required An array of product object IDs describing goods and quantities this invoice is for.
subtotal Optional Sum of the the all invoice product totals. Calculated automatically if not specified.
total Optional Total amount of the invoice up to 2 decimal digits. Minimal amount is 0.30.
discount_percent Optional The percentage of subtotal to discount the invoice for.
discount_amount Optional An amount to discount the invoice total for. Not less than zero and not more than the invoice subtotal.
vat_rate Optional VAT percentage for the invoice. Not more than two digits after decimal point.
vat_amount Optional Exact amount of VAT for the invoice. Generated automatically using vat_rate, if not specified.
number optional Payment unique reference number. Generated automatically, if isn’t specified.
fee_type optional Responsible side will cover the transaction fee. If not specified, option set in merchant’s profile settings will be used as default.

Possible values: merchant or client.

referrer optional There are various referrers depending on the platform the payment was created on. Possible referrer values: “profile”, “api”, “opencart”, etc.
comment optional Up to 125 ASCII symbols.
request_info Optional Merchant can request the client to specify particular details to complete the invoice. This information will be saved to the client object. Possible values: first_name, last_name, personal_code, company_name, legal_name, registration_nr, vat_payer_nr, address, iban, swift.
notes Optional Additional information on invoice for the client up to 10000 symbols.
language optional Two-letter language code to set payment interface language. If not specified, option set in merchant’s profile settings will be used as default.

Possible values: en, lv, lt, ru.

success_redirect optional You can set custom link for success redirect. If not specified, option set in API keys set settings will be used as default.
failure_redirect optional You can set custom link for failure redirect. If not specified, option set in API keys set settings will be used as default.
due_date optional The date payment is valid through in ISO 8601 format. If not specified set to 1 day by default.
timeout_seconds optional If specificed and greater than zero, your client will only have so many seconds to perform the payment, starting from the moment he opens the payment form. If it is specified it should be either 0 (timeout disabled, the default) or between 60 and 600 seconds (1 and 10 minutes, respectively).
skip_capture optional Skip immediate execution of this payment. Funds will be reserved for future payment execution or cancellation, see Execute a payment and Cancel a payment requests. Client will see the payment status as “hold” his bank statement during the reservation. Maximum reservation period depends on cardholder’s bank but usually is around one month.
custom_invoice_link optional You can set link to your online or PDF invoice.

Merchant server-side configurations required:
1. Merchant custom invoice link must be available over https.
2. Custom invoice response must return Access-Control-Allow-Origin: https://swipe.lv header.

Cancel a payment

POST https://swipe.lv/api/v0.5/payments/<id>/cancel/

You can cancel a payment using its payment id. Only unfinished and hold (created with "skip_capture": true and paid by the client) payments can be canceled, in the latter case fund reservation is returned to the client.

Payment statuses that allow cancellation: created, viewed, hold.

Execute a payment

POST https://swipe.lv/api/v0.5/payments/<id>/execute/

You can execute a reserved payment using its payment id. Only hold (created with "skip_capture": true and paid by the client) payments can be executed. This action transfers the funds previously reserved on client’s card to the merchant and notifies client about the payment just performed. If this command gets executed in more than a month (typical reservation timeout, depends on the client’s bank) from the moment client entered card data at, performing this action might fail.

Payment statuses that allow cancellation: hold.

Refund a payment

POST https://swipe.lv/api/v0.5/payments/<id>/refund/

You can refund a payment using its payment id.

Payment statuses that allow refunds: paid, withdrawn.

Retrieve a payment

GET https://swipe.lv/api/v0.5/payments/<id>/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/payments/384/'
request_method = 'GET'

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = getattr(requests, request_method.lower())(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization}
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$authorization_message = $timestamp.' GET /api/v0.5/payments/33/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'GET',
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/payments/33/ ', false, $context);
var_dump($result);
?>

Response example:

{
  "id": 326, 
  "hash": "6719a2d132bfaae43a99fd66b55fd521997ca9d8fc5da3ad69f075b15de60611", 
  "client": {
    "email": "test@example.com", 
    "phone": "", 
    "first_name": "", 
    "last_name": "", 
    "personal_code": "", 
    "company_name": "", 
    "legal_name": "", 
    "registration_nr": "", 
    "address": "", 
    "iban": ""
  }, 
  "amount": 2.75, 
  "due_date": "2016-02-12", 
  "timeout_seconds": 0,
  "fee": 0.28, 
  "fee_details": {
    "base_fee_amount": 0.2, 
    "fee_rate": 3.0
  }, 
  "fee_type": "merchant", 
  "deposit": 0.0, 
  "number": "TEST41", 
  "comment": "", 
  "refund_terms": "", 
  "language": "lv", 
  "date": null, 
  "status": "created",
  "skip_capture": false,
  "referrer": "", 
  "success_redirect": "", 
  "failure_redirect": "", 
  "custom_invoice_link": "", 
  "invoice_id": null, 
  "is_test": true, 
  "errors": [], 
  "timestamp": 1452615750
}

You can retrieve any payment using its payment id.

List all payments

GET https://swipe.lv/api/v0.5/payments/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/payments/'
request_method = 'GET'

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = getattr(requests, request_method.lower())(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization}
)
)
print response.text

<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$authorization_message = $timestamp.' GET /api/v0.5/payments/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'GET',
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/payments/ ', false, $context);
var_dump($result);
?>

Response example:

{
  "count": 7, 
  "items": [
    326, 
    325, 
    324, 
    323, 
    322, 
    321, 
    320, 

  ], 
  "has_more": false, 
  "errors": [], 
  "timestamp": 1452615864
}

You can retrieve a list of payments. This request supports pagination.

Example: ?limit=50&after_id=77

Parameter Description
ATTRIBUTES
limit Optional Number of objects per page, from 1 to 100 (100 by default).
after_id Optional ID of an object to fetch a page after (newest first).
before_id Optional ID of an object to fetch a page before (newest first).

Invoices

GET https://swipe.lv/client/payment/<hash>/

Using Swipe API you can generate and deliver invoices to your clients emails. If your merchant’s profile is verified, Swipe will create payment objects for invoices automatically. Payment object allows your clients to pay for invoices in two clicks. As well as, verification enables invoicing via SMS.

Events: invoice.expired

Parameter Description
ATTRIBUTES
id Integer, read-only Invoice unique identifier.
client Integer or Dictionary ID of the client object holding credentials of the recipient person or company.
products Dictionary An array of product object IDs describing goods and quantities this invoice is for.
due_date String The date invoice is valid through in ISO 8601 format. If not specified set to 1 month by default.
action String If not specified, action is set to send_email by default. If merchant profile is verified, Swipe automatically creates payment object for the invoice when it is sent.

Possible values: draft, send_email, send_sms, send_both, link.

link Sting, read-only Unique link for the invoice.
language String Two-letter language code to set payment interface language. If not specified, option set in merchant’s profile settings will be used as default. Possible values: en, lv, lt, ru.
request_info Array Merchant can request the client to specify particular details before making the payment. This information will be saved to the client object. Possible values: first_name, last_name, personal_code, company_name, legal_name, registration_nr, vat_payer_nr, address, iban, swift.
number String The unique invoice reference number. Generated automatically, if not specified.
date Date, read-only The date and time invoice was sent in ISO 8601 format.
notes String Additional information on invoice for the client up to 10000 symbols.
subtotal Decimal Sum of the the all invoice product totals. Calculated automatically if not specified.
discount_percent Integer The percentage of subtotal to discount the invoice for.
discount_amount Decimal An amount to discount the invoice total for. Not less than zero and not more than the invoice subtotal.
vat_rate Decimal VAT percentage for the invoice. Not more than two digits after decimal point.
vat_amount Decimal Exact amount of VAT for the invoice. Generated automatically using vat_rate, if not specified.
total Decimal Used in payment creation, indicates the amount of money to charge your client for. Not less than zero, minimal amount is 0.30, up to 2 decimal digits.
refund_terms String Merchant’s current refund terms.
custom_invoice_link String Specify link to the invoice webpage or PDF file.
status String, read-only A string that can have draft, sent, viewed, canceled, expired, link or received values.
referrer String, read-only There are various referrers depending on the platform the payment was created. Such as “profile”, “api”, “opencart”, etc.
payment_id Integer, read-only Payment object ID connected to the invoice, if there is one. Available only for verified merchants.

Send an invoice

POST https://swipe.lv/api/v0.5/invoices/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/invoices/'
request_method = 'POST'

data = {
    'client': {
        'email': 'john.smith@example.com'
    },
    'products': [
        {
            'description': 'Green tea XL pack', 
            'price': 28.50, 
            'quantity': 5
        },
        {
            'description': 'Black tea M pack', 
            'price': 12.35, 
            'quantity': 2
        }
    ],
}
request_body = json.dumps(data)

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = requests.post(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization},
    data = request_body
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$params = json_encode(
array(
    'client' => array('email' => 'john.shmith@examples.com'), 
    'products' => array(
        array(
            'description' => 'Green tea XL pack', 
            'price' => 28.50, 
            'quantity' => 5
        ), 
        array(
            'description' => 'Black tea M pack', 
            'price' => 12.35, 
            'quantity' => 2
        ))
    )
);

$authorization_message = $timestamp.' POST /api/v0.5/invoices/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'POST',
        'content' => $params,
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/invoices/ ', false, $context);
var_dump($result);
?>

Response example:

{
  "full_page_checkout": "https://swipe.lv/client/payment/979ffe8e8e74dfcce30c517aca07a5f848ddf8bf2e079080f8b623a2e59afdd8/full_page/",
  "iframe_checkout": "https://swipe.lv/client/payment/979ffe8e8e74dfcce30c517aca07a5f848ddf8bf2e079080f8b623a2e59afdd8/iframe/",
  "id": 185,
  "errors": [],
  "timestamp": 1449584589
}

When sending the invoice you can request your client to specify particular details to complement it. If your merchant’s profile is verified when you set action attribute to send_email, send_sms, send_both or link, Swipe also automatically creates a payment object for the invoice. You can specify payment object attributes in the same request. If you want to create the invoice without sending it, just set action attribute to draft. If you just want to receive a link for the invoice and deliver it on your own, set action attribute to link.

Parameter Description
ATTRIBUTES
client Required ID of the client object holding credentials of the recipient person or company.
products Required An array of product object IDs describing goods and quantities this invoice is for.
due_date Optional The date invoice is valid through in ISO 8601 format. If not specified set to 1 month by default.
action Optional If not specified, action is set to send_email by default. If merchant profile is verified, Swipe automatically creates payment object for the invoice when it is sent.

Possible values: draft, send_email, send_sms, send_both, link.

language Optional Two-letter language code to set payment interface language. If not specified, option set in merchant’s profile settings will be used as default. Possible values: en, lv, lt, ru.
request_info Optional Merchant can request the client to specify particular details to complete the invoice. This information will be saved to the client object. Possible values: first_name, last_name, personal_code, company_name, legal_name, registration_nr, vat_payer_nr, address, iban, swift.
number Optional The unique invoice reference number. Generated automatically, if not specified.
notes Optional Additional information on invoice for the client up to 10000 symbols.
subtotal Optional Sum of the the all invoice product totals. Calculated automatically if not specified.
discount_percent Optional The percentage of subtotal to discount the invoice for.
discount_amount Optional An amount to discount the invoice total for. Not less than zero and not more than the invoice subtotal.
vat_rate Optional VAT percentage for the invoice. Not more than two digits after decimal point.
vat_amount Optional Exact amount of VAT for the invoice. Generated automatically using vat_rate, if not specified.
total Optional Total amount of the invoice up to 2 decimal digits. Minimal amount is 0.30.
referrer Optional There are various referrers depending on the platform the payment was created. Such as “profile”, “api”, “opencart”, etc.

Send a custom invoice

If you want to use your own design and template for invoices, you can use Swipe as a notification and payment system. Your invoices will be powered up with reminders and instant payments. All you need is to specify the link to invoice webpage or PDF file. Your custom invoice will be dispalyed clicking on view invoice in the notification or previewing it during the payment process.

If you want to receive a link for the invoice and deliver it on your own, set action attribute to link. If your merchant’s profile is verified when you set action attribute to send_email, send_sms, send_both or link, Swipe also automatically creates a payment object for the invoice. You can specify payment object attributes in the same request.

Parameter Description
ATTRIBUTES
client Required ID of the client object holding credentials of the recipient person or company.
custom_invoice_link Required Specify the link to invoice webpage or PDF file.
due_date Optional The date invoice is valid through in ISO 8601 format. If not specified set to 1 month by default.
action Optional If not specified, action is set to send_email by default. If merchant profile is verified, Swipe automatically creates payment object for the invoice when it is sent.

Possible values: draft, send_email, send_sms, send_both, link.

language Optional Two-letter language code to set payment interface language. If not specified, option set in merchant’s profile settings will be used as default. Possible values: en, lv, lt, ru.
request_info Optional Merchant can request the client to specify particular details to complete the invoice. This information will be saved to the client object. Possible values: first_name, last_name, personal_code, company_name, legal_name, registration_nr, vat_payer_nr, address, iban, swift.
number Optional The unique invoice reference number. Generated automatically, if not specified.
total Optional Total amount of the invoice up to 2 decimal digits. Minimal amount is 0.30.
referrer Optional There are various referrers depending on the platform the payment was created. Such as “profile”, “api”, “opencart”, etc.

Cancel an invoice

POST https://swipe.lv/api/v0.5/invoices/<id>/cancel/

You can cancel invoice using its payment id. Only unpaid invoices can be canceled.

Invoice statuses that allow cancellation: sent, viewed, link.

Update a draft

PUT https://swipe.lv/api/v0.5/invoices/<id>/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/invoices/324/'
request_method = 'PUT'

data = {
    'notes': 'Additional information'
}
request_body = json.dumps(data)

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = getattr(requests, request_method.lower())(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization},
    data = request_body
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$params = json_encode(
    array( 'action' => 'send_email')
);

$authorization_message = $timestamp.' PUT /api/v0.5/invoices/35/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'PUT',
        'content' => $params,
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/invoices/35/ ', false, $context);
var_dump($result);
?>

You can update any draft invoice using its invoice id. If you want to send an invoice you have previously created as a draft set action attribute to send_email, send_sms or send_both. If you want to receive a link for the invoice and deliver it on your own, set action attribute to link.

If your merchant’s profile is verified when you set action attribute to send_email, send_sms, send_both or link, Swipe also automatically creates a payment object for the invoice. You can specify payment object attributes in the same request.

Parameter Description
ATTRIBUTES
client Required ID of the client object holding credentials of the recipient person or company.
products Required An array of product object IDs describing goods and quantities this invoice is for.
due_date Optional The date invoice is valid through in ISO 8601 format. If not specified set to 1 month by default.
action Optional If not specified, action is set to send_email by default. If merchant profile is verified, Swipe automatically creates payment object for the invoice when it is sent.

Possible values: draft, send_email, send_sms, send_both, link.

language Optional Two-letter language code to set payment interface language. If not specified, option set in merchant’s profile settings will be used as default. Possible values: en, lv, lt, ru.
request_info Optional Merchant can request the client to specify particular details before making the payment. This information will be saved to the client object. Possible values: first_name, last_name, personal_code, company_name, legal_name, registration_nr, vat_payer_nr, address, iban, swift.
number Optional The unique invoice reference number. Generated automatically, if not specified.
date Optional The date and time invoice was sent in ISO 8601 format.
notes Optional Additional information on invoice for the client up to 10000 symbols.
subtotal Optional Sum of the the all invoice product totals. Calculated automatically if not specified.
discount_percent Optional The percentage of subtotal to discount the invoice for.
discount_amount Optional An amount to discount the invoice total for. Not less than zero and not more than the invoice subtotal.
vat_rate Optional VAT percentage for the invoice. Not more than two digits after decimal point.
vat_amount Optional Exact amount of VAT for the invoice. Generated automatically using vat_rate, if not specified.
total Optional Total amount of the invoice up to 2 decimal digits. Minimal amount is 0.30.
referrer Optional There are various referrers depending on the platform the payment was created. Such as “profile”, “api”, “opencart”, etc.

Delete a draft

DELETE https://swipe.lv/api/v0.5/invoices/<id>/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/invoices/324/'
request_method = 'DELETE'

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = getattr(requests, request_method.lower())(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization}
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$authorization_message = $timestamp.' DELETE /api/v0.5/invoices/35/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'DELETE',
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/invoices/35/ ', false, $context);
var_dump($result);
?>

You can delete the invoice using its id. Only invoices with current status draft can be deleted.

Retrieve an invoice

GET https://swipe.lv/api/v0.5/invoices/<id>/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/invoices/183/'
request_method = 'GET'

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = getattr(requests, request_method.lower())(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization}
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$authorization_message = $timestamp.' GET /api/v0.5/invoices/35/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'GET',
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/invoices/35/ ', false, $context);
var_dump($result);
?>

Response example:

{
  "id": 328, 
  "client": {
    "email": "john.smith@example.com", 
    "phone": "", 
    "first_name": "", 
    "last_name": "", 
    "personal_code": "", 
    "company_name": "", 
    "legal_name": "", 
    "registration_nr": "", 
    "address": "", 
    "iban": ""
  }, 
  "products": [
    {
      "description": "Green tea XL pack", 
      "price": 28.5, 
      "quantity": 5.0
    }, 
    {
      "description": "Black tea M pack", 
      "price": 12.35, 
      "quantity": 2.0
    }
  ], 
  "due_date": "2016-02-12", 
  "fee_type": "merchant", 
  "action": "send_email", 
  "link": "http://127.0.0.1:8000/lv/i/05Ei34a5741c", 
  "language": "lv", 
  "request_info": [], 
  "number": "TEST43", 
  "comment": "", 
  "date": "2016-01-12T21:27:58.659260+00:00", 
  "notes": "", 
  "subtotal": 202.31, 
  "discount_percent": 0, 
  "discount_amount": 0.0, 
  "vat_rate": 0.21, 
  "vat_amount": 35.11, 
  "total": 40.85, 
  "status": "sent", 
  "custom_invoice_link": null, 
  "referrer": "", 
  "payment_id": 328, 
  "errors": [], 
  "timestamp": 1452635208
}

You can retrieve any invoice using its id.

List all invoices

GET https://swipe.lv/api/v0.5/invoices/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/invoices/'
request_method = 'GET'

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = requests.post(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization}
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$authorization_message = $timestamp.' GET /api/v0.5/invoices/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'GET',
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/invoices/ ', false, $context);
var_dump($result);
?>

Response example:

{
  "count": 6, 
  "items": [ 
    182, 
    181, 
    180, 
    179, 
    178, 
    177
  ], 
  "has_more": false, 
  "errors": [], 
  "timestamp": 1447668000
}

You can retrieve a list of invoices. This request supports pagination.

Example: ?limit=50&after_id=77

Parameter Description
ATTRIBUTES
limit Optional Number of objects per page, from 1 to 100 (100 by default).
after_id Optional ID of an object to fetch a page after (newest first).
before_id Optional ID of an object to fetch a page before (newest first).

Subscriptions

Automated subscriptions make sure businesses receive recurring payments fast, without interrupting clients’ day with unnecessary reminders. You can add customers to any subscription manually in merchant’s Swipe account, via API. Clients also can subscribe online on your website using the payment form. For clients subscribing online automated payments are enabled by default.

Parameter Description
ATTRIBUTES
id Integer, read-only Subscription unique identifier.
base_invoice Dictionary, read-only Subscription invoice.
clients_count Integer, read-only Subscription’s number of clients.
name String Subscription name, up to 254 digits.
start_date String Subscription start date and time in ISO 8601 format.
billing_period_length Integer Billing period, control how often invoices will be sent. If not specified, billing period is set to 1 by default.
billing_period_units String Specify billing period units. If not specified, billing period unit is set to m by default. Possible values: d - day, w - week, m - month, y - year.
postpay_mode boolean If mode is true, clients receive the first invoice once the first billing period ends.
status Integer If not specified, action is set to draft by default. Possible values: 0 - draft, 1 - paused, 2 - active, 3 - expired.

Create a subscription

POST https://swipe.lv/api/v0.5/subscriptions/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/subscriptions/'
request_method = 'POST'

data = {
    "start_date": "2019-09-22T13:10:27",
    "name": "API test subscription"
}
request_body = json.dumps(data)

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = getattr(requests, request_method.lower())(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization},
    data = request_body
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$params = json_encode(array(
    'start_date' => '2019-09-22T13:10:27', 
    'name' => 'API test subscription')
);

$authorization_message = $timestamp.' POST /api/v0.5/subscriptions/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'POST',
        'content' => $params,
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/subscriptions/ ', false, $context);
var_dump($result);
?>

Response example:

{
  "id": 55, 
  "errors": [], 
  "timestamp": 1473701315
}

You can add and edit subscription details in merchant’s Swipe account or using API.

Parameter Description
ATTRIBUTES
name Required Subscription name, up to 254 digits.
start_date Required Subscription start date and time in ISO 8601 format.
billing_period_length optional Billing period, control how often invoices will be sent. If not specified, billing period is set to 1 by default.
billing_period_units optional Specify billing period units. If not specified, billing period unit is set to m by default. Possible values: d - day, w - week, m - month, y - year.
postpay_mode optional If mode is true, clients receive the first invoice once the first billing period ends.
status optional If not specified, action is set to draft by default. Possible values: 0 - draft, 1 - paused, 2 - active, 3 - expired.

Update a subscription

PUT https://swipe.lv/api/v0.5/subscriptions/<id>/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/subscriptions/31/'
request_method = 'PUT'

data = {
    "name": "API test subscription"
}
request_body = json.dumps(data)

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = getattr(requests, request_method.lower())(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization},
    data = request_body
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$params = json_encode(array( 
    'name' => 'API test subscription')
);

$authorization_message = $timestamp.' PUT /api/v0.5/subscriptions/31/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'PUT',
        'content' => $params,
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/subscriptions/31/ ', false, $context);
var_dump($result);
?>

You can edit and update any subscription details using its product id.

Parameter Description
ATTRIBUTES
name Required Subscription name, up to 254 digits.
start_date Required Subscription start date and time in ISO 8601 format.
billing_period_length optional Billing period, control how often invoices will be sent. If not specified, billing period is set to 1 by default.
billing_period_units optional Specify billing period units. If not specified, billing period unit is set to m by default. Possible values: d - day, w - week, m - month, y - year.
postpay_mode optional If mode is true, clients receive the first invoice once the first billing period ends.
status optional If not specified, action is set to draft by default. Possible values: 0 - draft, 1 - paused, 2 - active, 3 - expired.

Delete a subscription

DELETE https://swipe.lv/api/v0.5/subscriptions/<id>/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/subscriptions/31/'
request_method = 'DELETE'

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = getattr(requests, request_method.lower())(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization}
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$authorization_message = $timestamp.' DELETE /api/v0.5/subscriptions/31/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'DELETE',
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/subscriptions/31/ ', false, $context);
var_dump($result);
?>

You can delete any subscription using its id.

Retrieve a subscription

GET https://swipe.lv/api/v0.5/subscriptions/<id>/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/subscriptions/31/'
request_method = 'GET'

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = getattr(requests, request_method.lower())(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization}
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$authorization_message = $timestamp.' GET /api/v0.5/subscriptions/31/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'GET',
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/subscriptions/31/ ', false, $context);
var_dump($result);
?>

Response example:

{
  "id": 32, 
  "name": "Car washing", 
  "start_date": "2016-07-27", 
  "billing_period_units": "w", 
  "billing_period_length": 3, 
  "postpay_mode": true, 
  "due_days": 14, 
  "status": 2, 
  "base_invoice": {
    "id": 458, 
    "client": {
      "email": "john.smith@examples.com", 
      "phone": "", 
      "first_name": "", 
      "last_name": "", 
      "personal_code": "", 
      "company_name": "", 
      "legal_name": "", 
      "registration_nr": "", 
      "address": "", 
      "iban": ""
    }, 
    "products": [
      {
        "description": "Washing", 
        "price": 13.34, 
        "quantity": 1.0
      }
    ], 
    "timeout_seconds": 0, 
    "due_date": null, 
    "fee_type": "merchant", 
    "action": null, 
    "link": null, 
    "language": "en", 
    "request_info": [], 
    "number": "SW10", 
    "comment": "", 
    "date": null, 
    "notes": "", 
    "subtotal": 0.0, 
    "discount_percent": 0, 
    "discount_amount": 0.0, 
    "vat_rate": 0.21, 
    "vat_amount": 0.0, 
    "vat_enabled": false, 
    "total": 0.0, 
    "status": "draft", 
    "success_redirect": null, 
    "failure_redirect": null, 
    "callback": null, 
    "custom_invoice_link": null, 
    "referrer": "", 
    "payment_id": null, 
    "creation_channel": 10
  }, 
  "clients_count": 1, 
  "creation_channel": 10, 
  "errors": [], 
  "timestamp": 1473701209
}

You can retrieve any subscription using its id.

List all subscriptions

GET https://swipe.lv/api/v0.5/subscriptions/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/subscriptions/'
request_method = 'GET'

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = getattr(requests, request_method.lower())(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization}
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$authorization_message = $timestamp.' GET /api/v0.5/subscriptions/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'GET',
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/subscriptions/ ', false, $context);
var_dump($result);
?>

Response example:

{
  "count": 6, 
  "items": [
    38, 
    37, 
    36, 
    33, 
    32, 
    31
  ], 
  "has_more": false, 
  "errors": [], 
  "timestamp": 1473701141
}

You can retrieve a list of subscriptions. This request supports pagination.

Example: ?limit=50&after_id=77

Parameter Description
ATTRIBUTES
limit Optional Number of objects per page, from 1 to 100 (100 by default).
after_id Optional ID of an object to fetch a page after (newest first).
before_id Optional ID of an object to fetch a page before (newest first).

Create the subscription’s invoice

POST https://swipe.lv/api/v0.5/subscriptions/<id>/invoice/

Subscription invoice creation is identical to invoice creation.

Update the subscription’s invoice

PUT https://swipe.lv/api/v0.5/subscriptions/<id>/invoice/

Subscription invoice updating is identical to invoice updating.

Retrieve the subscription’s invoice

GET https://swipe.lv/api/v0.5/subscriptions/<id>/invoice/

You can retrieve subscription invoice using subscription id.

Subscription client

You can add and edit subscription client details in merchant’s Swipe account or API.

Parameter Description
ATTRIBUTES
id Integer, read-only Subscription client unique identifier.
client Integer ID of the client object holding credentials of the recipient person or company.
override_next_billing_date String Subscription client billing date and time in ISO 8601 format.
send_to Integer If not specified, action is set to 2 by default. Possible values: 0 - email, 1 - phone, 2 - email and phone, 3 - pause.

Add a subscription client

POST https://swipe.lv/api/v0.5/subscriptions/<id>/clients/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/subscriptions/31/clients/'
request_method = 'POST'

data = {
    "override_next_billing_date": "2019-09-22T13:10:27",
    "send_to": 2,
    "client": 40  
}
request_body = json.dumps(data)

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = getattr(requests, request_method.lower())(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization},
    data = request_body
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$params = json_encode(array(
    'override_next_billing_date' => '2019-09-22T13:10:27', 
    'send_to' => 2,
    'client' => 40)
);

$authorization_message = $timestamp.' POST /api/v0.5/subscriptions/31/clients/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'POST',
        'content' => $params,
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/subscriptions/31/clients/ ', false, $context);
var_dump($result);
?>

Response example:

{
  "id": 51, 
  "errors": [], 
  "timestamp": 1473702178
}

You have to specify at least one subscription client to activate subscription.

Parameter Description
ATTRIBUTES
client Required ID of the client object holding credentials of the recipient person or company.
override_next_billing_date Required Subscription client billing date and time in ISO 8601 format.
send_to optional If not specified, action is set to 2 by default. Possible values: 0 - email, 1 - phone, 2 - email and phone, 3 - pause.

Update a subscription client

PUT https://swipe.lv/api/v0.5/subscriptions/<id>/clients/<id>/
import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/subscriptions/31/clients/27/'
request_method = 'PUT'

data = {
    "send_to": 1  
}
request_body = json.dumps(data)

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = getattr(requests, request_method.lower())(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization},
    data = request_body
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$params = json_encode(array( 
    'send_to' => 2)
);

$authorization_message = $timestamp.' PUT /api/v0.5/subscriptions/31/clients/27/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'PUT',
        'content' => $params,
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/subscriptions/31/clients/27/ ', false, $context);
var_dump($result);
?>

You can edit and update any subscription client using subscription id and client id.

Parameter Description
ATTRIBUTES
client Required ID of the client object holding credentials of the recipient person or company.
override_next_billing_date Required Subscription client billing date and time in ISO 8601 format.
send_to optional If not specified, action is set to 2 by default. Possible values: 0 - email, 1 - phone, 2 - email and phone, 3 - pause.

Delete a subscription client

DELETE https://swipe.lv/api/v0.5/subscriptions/<id>/clients/<id>/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/subscriptions/31/clients/27/'
request_method = 'DELETE'

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = getattr(requests, request_method.lower())(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization}
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$authorization_message = $timestamp.' DELETE /api/v0.5/subscriptions/31/clients/27/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'DELETE',
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/subscriptions/31/clients/27/ ', false, $context);
var_dump($result);
?>

You can delete any subscription client using subscription id and client id.

Retrieve a subscription client

GET https://swipe.lv/api/v0.5/subscriptions/<id>/clients/<id>/
import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/subscriptions/31/clients/27/'
request_method = 'GET'

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = getattr(requests, request_method.lower())(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization}
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$authorization_message = $timestamp.' GET /api/v0.5/subscriptions/31/clients/27/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'GET',
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/subscriptions/31/clients/27/ ', false, $context);
var_dump($result);
?>

Response example:

{
  "id": 34, 
  "client": {
    "id": 42, 
    "email": "john.smith@examples.com", 
    "phone": "", 
    "first_name": "", 
    "last_name": "", 
    "personal_code": "", 
    "company_name": "", 
    "legal_name": "", 
    "registration_nr": "", 
    "address": "", 
    "iban": ""
  }, 
  "override_next_billing_date": "2016-09-10", 
  "override_due_days": null, 
  "send_to": 2, 
  "recurring_paused": false, 
  "last_invoice": null, 
  "send_next_invoice": true, 
  "errors": [], 
  "timestamp": 1473702751
}

You can retrieve any subscription client using subscription id and client id.

List all subscription clients

GET https://swipe.lv/api/v0.5/subscriptions/<id>/clients/
import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/subscriptions/31/clients/'
request_method = 'GET'

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = getattr(requests, request_method.lower())(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization}
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$authorization_message = $timestamp.' GET /api/v0.5/subscriptions/31/clients/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'GET',
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/subscriptions/31/clients/ ', false, $context);
var_dump($result);
?>

Response example:

{
  "count": 5, 
  "items": [
    34, 
    33, 
    32, 
    31, 
    28
  ], 
  "has_more": false, 
  "errors": [], 
  "timestamp": 1473702807
}

You can retrieve a list of subscriptions. This request supports pagination.

Example: ?limit=50&after_id=77

Parameter Description
ATTRIBUTES
limit Optional Number of objects per page, from 1 to 100 (100 by default).
after_id Optional ID of an object to fetch a page after (newest first).
before_id Optional ID of an object to fetch a page before (newest first).

Transfers

Transfer is a group of withdrawn payments. If there is at least one payment made, Swipe automatically creates a new transfer and adds the payment to it. Merchant can set up automatic withdrawals to IBAN as well as request transfer manually at any time.

For some countries and merchants with higher risk probabilities insurance deposit may be applied. In this case each payment is withdrawn in two parts. Insurance deposit’s rate and period can differ, but by default it is 10% for 120 days. If merchant has made any refunds, funds to cover them will be withheld from the next transfer or insurance deposit.

Parameter Description
ATTRIBUTES
id Integer, read-only Transfer unique identifier.
number String, read-only Batch identifier that will appear in your bank transfer description, up to 32 symbols.
date Date, read-only Date of transfer withdrawal, if applicable.
iban String, read-only IBAN funds were transferred to.
swift String, read-only SWIFT code of the bank funds were transferred to.
transfer_amount Integer, read-only Total amount transferred.
payment_amount Integer, read-only Sum of payments transferred.
deposit_amount Integer, read-only Sum of insurance deposits transferred.

Retrieve the upcoming transfer

GET https://swipe.lv/api/v0.5/transfers/upcoming/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/transfers/upcoming/'
request_method = 'GET'

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = requests.post(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization}
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$authorization_message = $timestamp.' GET /api/v0.5/transfers/upcoming/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'GET',
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/transfers/upcoming/ ', false, $context);
var_dump($result);
?>

Response example:

{
  "id": 14, 
  "number": "SWIPE1", 
  "date": "2015-11-16T14:18", 
  "iban": "LV80 RTMB 0007 0070 0700 70", 
  "swift": "LVRTMB22", 
  "deposit": 0.00, 
  "transfer_amount": 64.77, 
  "payment_amount": 64.77, 
  "errors": [], 
  "timestamp": 1447668000
}

You can request the next transfer amount by retrieving the upcoming transfer.

Events: transfer.withdrawn

Retrieve a transfer

GET https://swipe.lv/api/v0.5/transfers/<id>/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/transfers/14/'
request_method = 'GET'

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = requests.post(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization}
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$authorization_message = $timestamp.' GET /api/v0.5/transfers/14/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'GET',
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/transfers/14/ ', false, $context);
var_dump($result);
?>

Response example:

{
  "id": 14, 
  "number": "SWIPE1", 
  "date": "2015-11-16T14:18", 
  "iban": "LV80 RTMB 0007 0070 0700 70", 
  "swift": "LVRTMB22", 
  "deposit": 0.00, 
  "transfer_amount": 64.77, 
  "payment_amount": 64.77, 
  "errors": [], 
  "timestamp": 1447668000
}

You can retrieve any transfer using its payment id.

List all payments of a transfer

GET https://swipe.lv/api/v0.5/transfers/<id>/payments/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/transfers/14/payments/'
request_method = 'GET'

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = requests.post(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization}
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$authorization_message = $timestamp.' GET /api/v0.5/transfers/14/payments/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'GET',
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/transfers/14/payments/ ', false, $context);
var_dump($result);
?>

Response example:

{
  "invoices": [
    56, 
    57
  ], 
  "rollings": [
    34
  ], 
  "errors": [], 
  "timestamp": 1447668000
}

You can retrieve list of payments in the transfer using transfer id.

List all transfers

GET https://swipe.lv/api/v0.5/transfers/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/transfers/'
request_method = 'GET'

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = requests.post(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization}
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$authorization_message = $timestamp.' GET /api/v0.5/transfers/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'GET',
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/transfers/ ', false, $context);
var_dump($result);
?>

Response example:

{
  "count": 5, 
  "items": [
    5, 
    4, 
    3,
    2,
    1
  ], 
  "has_more": false, 
  "errors": [], 
  "timestamp": 1447668000
}

You can retrieve a list of transfers. This request supports pagination.

Example: ?limit=50&after_id=77

Parameter Description
ATTRIBUTES
limit Optional Number of objects per page, from 1 to 100 (100 by default).
after_id Optional ID of an object to fetch a page after (newest first).
before_id Optional ID of an object to fetch a page before (newest first).

Balance

Swipe balance consists of two parts: upcoming transfer and amount of insurance deposit.

Parameter Description
ATTRIBUTES
balance Integer, read-only Amount of funds on your Swipe account.
deposit Integer, read-only Amount of funds held as an insurance deposit.

Retrieve balance

GET https://swipe.lv/api/v0.5/balance/

You can request the amount of total funds available on your Swipe account by retrieving the balance.

Clients

You can add and edit client details in merchant’s Swipe account, using API or request a client to specify them upon paying the invoice.

Parameter Description
ATTRIBUTES
id Integer, read-only Client unique identifier.
email String Client’s email, up to 254 digits. Optional, if phone is set.
phone String Client’s phone number, up to 32 digits. Optional, if email is set.
first_name String First name of the client, up to 64 symbols.
last_name String Last name of the client, up to 64 symbols.
personal_code String Personal code or other nation-wide identifier of this client, up to 32 symbols.
company_name String Brand name or other kind of unofficial name of the client company, up to 128 symbols.
legal_name String Legal name of the client company, up to 128 symbols.
registration_nr String Registration number of the client company, up to 32 symbols.
vat_payer_nr String VAT payer number of the client company, up to 32 symbols.
address String Legal (officially registered) address of the client company, up to 128 symbols.
iban String IBAN of client’s bank account, up to 34 symbols.
swift String SWIFT/BIC code of client’s bank, up to 11 symbols.

Create a client

POST https://swipe.lv/api/v0.5/clients/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/clients/'
request_method = 'POST'

data = {
    "email": "john.smith@examples.com",
    "first_name": "John"
}
request_body = json.dumps(data)

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = getattr(requests, request_method.lower())(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization},
    data = request_body
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$params = json_encode(array(
    'email' => 'john.smith@examples.com', 
    'first_name' => 'John')
);

$authorization_message = $timestamp.' POST /api/v0.5/clients/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'POST',
        'content' => $params,
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/clients/ ', false, $context);
var_dump($result);
?>

Response:

{
  "id": 20, 
  "errors": [], 
  "timestamp": 1447668000
}

Merchant has to specify a client for each payment or invoice.

Parameter Description
ATTRIBUTES
email Required Client’s email, up to 254 digits. Optional, if phone is set.
phone Required Client’s phone, up to 32 digits. Optional, if email is set.
first_name Optional First name of the client, up to 64 symbols.
last_name Optional Last name of the client, up to 64 symbols.
personal_code Optional Personal code or other nation-wide identifier of this client, up to 32 symbols.
company_name Optional Brand name or other kind of unofficial name of the client company, up to 128 symbols.
legal_name Optional Legal name of the client company, up to 128 symbols.
registration_nr Optional Registration number of the client company, up to 32 symbols.
vat_payer_nr Optional VAT payer number of the client company, up to 32 symbols.
address Optional Legal (officially registered) address of the client company, up to 128 symbols.
iban Optional IBAN of client’s bank account, up to 34 symbols.
swift Optional SWIFT/BIC code of client’s bank, up to 11 symbols.

Update a client

PUT https://swipe.lv/api/v0.5/clients/<id>/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/clients/17/'
request_method = 'PUT'

data = {
    "email": "john.smith@examples.com",
    "first_name": "John"
}
request_body = json.dumps(data)

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = getattr(requests, request_method.lower())(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization},
    data = request_body
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$params = json_encode(array(
    'email' => 'john.smith@examples.com', 
    'first_name' => 'John')
);

$authorization_message = $timestamp.' PUT /api/v0.5/clients/20/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'PUT',
        'content' => $params,
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/clients/20/ ', false, $context);
var_dump($result);
?>

You can edit and update any client details using its product id.

Parameter Description
ATTRIBUTES
email Required Client email, up to 254 digits. Is optional if phone is set.
phone Required Client phone, up to 32 digits. Is optional if email is set.
first_name Optional First name of the client, up to 64 symbols.
last_name Optional Last name of the client, up to 64 symbols.
personal_code Optional Personal code or other nation-wide identifier of this client, up to 32 symbols.
company_name Optional Brand name or other kind of unofficial name of the client company, up to 128 symbols.
legal_name Optional Legal name of the client company, up to 128 symbols.
registration_nr Optional Registration number of the client company, up to 32 symbols.
vat_payer_nr String VAT payer number of the client company, up to 32 symbols.
address Optional Legal (officially registered) address of the client company, up to 128 symbols.
iban Optional IBAN of client’s bank account, up to 34 symbols.
swift Optional SWIFT/BIC code of client’s bank, up to 11 symbols.

Delete a client

DELETE https://swipe.lv/api/v0.5/clients/<id>/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/clients/15/'
request_method = 'DELETE'

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = getattr(requests, request_method.lower())(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization}
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$authorization_message = $timestamp.' DELETE /api/v0.5/clients/20/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'DELETE',
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/clients/20/ ', false, $context);
var_dump($result);
?>

You can delete any client using its id.

Retrieve a client

GET https://swipe.lv/api/v0.5/clients/<id>/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/clients/15/'
request_method = 'GET'

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = getattr(requests, request_method.lower())(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization}
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$authorization_message = $timestamp.' GET /api/v0.5/clients/20/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'GET',
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/clients/20/ ', false, $context);
var_dump($result);
?>

Response example:

{
  "id": 34, 
  "email": "john.smith@examples.com", 
  "phone": "", 
  "first_name": "John", 
  "last_name": "", 
  "personal_code": "", 
  "company_name": "", 
  "legal_name": "", 
  "registration_nr": "", 
  "address": "", 
  "iban": "", 
  "errors": [], 
  "timestamp": 1452635911
}

You can retrieve any client using its id.

List all clients

GET https://swipe.lv/api/v0.5/clients/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/clients/'
request_method = 'GET'

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = getattr(requests, request_method.lower())(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization}
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$authorization_message = $timestamp.' GET /api/v0.5/clients/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'GET',
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/clients/ ', false, $context);
var_dump($result);
?>

Response example:

{
  "count": 5, 
  "items": [
    4109, 
    3821, 
    2036, 
    1524, 
    1418
  ], 
  "has_more": false, 
  "errors": [], 
  "timestamp": 1447668000
}

You can retrieve a list of clients. This request supports pagination.

Example: ?limit=50&after_id=77

Parameter Description
ATTRIBUTES
limit Optional Number of objects per page, from 1 to 100 (100 by default).
after_id Optional ID of an object to fetch a page after (newest first).
before_id Optional ID of an object to fetch a page before (newest first).

Products

For you to create the invoices even faster products hold information about the goods you sell.

Parameter Description
ATTRIBUTES
id Integer, read-only Product unique identifier.
description String A description to display in invoices, up to 255 characters.
price Decimal Price for a single unit. Up to 10 digits in total, up to 2 decimal digits.

Create a product

POST https://swipe.lv/api/v0.5/products/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/products/'
request_method = 'POST'

data = {
    'description': 'Green tea XL pack',
    'price': 8.50
}
request_body = json.dumps(data)

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = getattr(requests, request_method.lower())(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization},
    data = request_body
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$params = json_encode(array(
    'description' => 'Green tea XL pack', 'price' => 8.50)
);

$authorization_message = $timestamp.' POST /api/v0.5/products/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
        'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'POST',
        'content' => $params,
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/products/', false, $context);
echo $result;
?>

Response example:

{
  "id": 1, 
  "errors": [], 
  "timestamp": 1447668000
}

You have to specify at least one product to create the invoice.

Parameter Description
ATTRIBUTES
description Required Product description to display in invoices, up to 255 chars.
price Required Price for a single unit. Up to 10 digits in total and up to 2 decimal digits.

Update a product

PUT https://swipe.lv/api/v0.5/products/<id>/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/products/1/'
request_method = 'PUT'

data = {
    'price': 9.50
}
request_body = json.dumps(data)

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = getattr(requests, request_method.lower())(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization},
    data = request_body
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$params = json_encode(array(
    'description' => 'Green tea XL pack', 'price' => 8.50)
);

$authorization_message = $timestamp.' PUT /api/v0.5/products/7/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
        'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'PUT',
        'content' => $params,
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/products/7/ ', false, $context);
echo $result;
?>

You can edit and update any product information using its product id

Parameter Description
ATTRIBUTES
description Required Product description to display in invoices, up to 255 chars.
price Required Price for a single unit. Up to 10 digits in total and up to 2 decimal digits.

Delete a product

DELETE https://swipe.lv/api/v0.5/products/<id>/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/products/27/'
request_method = 'DELETE'

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = getattr(requests, request_method.lower())(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization}
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$authorization_message = $timestamp.' DELETE /api/v0.5/products/7/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
        'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'DELETE',
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/products/7/ ', false, $context);
echo $result;
?>

You can delete any product using its id.

Retrieve a product

GET https://swipe.lv/api/v0.5/products/<id>/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/products/27/'
request_method = 'GET'

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = getattr(requests, request_method.lower())(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization}
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$authorization_message = $timestamp.' GET /api/v0.5/products/7/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
        'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'GET',
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/products/7/ ', false, $context);
echo $result;
?>

Response example:

{
  "id": 1340, 
  "description": "White tea XL pack", 
  "price": 55.00, 
  "errors": [], 
  "timestamp": 1447668000
}

You can retrieve any product using its id.

List all products

GET https://swipe.lv/api/v0.5/products/

Code example:

import time, json, hmac, hashlib, requests

public_key = '<public key>'
private_key = '<private key>'
timestamp = str(int(time.time()))

request_link = '/api/v0.5/products/'
request_method = 'GET'

authorization = ' '.join([timestamp, request_method, request_link, request_body])
authorization = hmac.new(private_key, authorization, hashlib.sha256).hexdigest()
authorization = ','.join([public_key, timestamp, authorization])

response = getattr(requests, request_method.lower())(
    'https://swipe.lv' + request_link,
    headers = {'Authorization': authorization}
)
print response.text
<?php
$public_key = '<public key>'
$private_key = '<private key>'
$timestamp = (string)time();

$authorization_message = $timestamp.' GET /api/v0.5/products/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;

$options = array(
        'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
        'method'  => 'GET',
        'ignore_errors' => true
    ),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/products/ ', false, $context);
echo $result;
?>

Response example:

{
  "count": 5, 
  "items": [
    2378, 
    2371, 
    974, 
    973, 
    928
  ], 
  "has_more": false, 
  "errors": [], 
  "timestamp": 1447668000
}

You can retrieve a list of products. This request supports pagination.

Example: ?limit=50&after_id=77

Parameter Description
ATTRIBUTES
limit Optional Number of objects per page, from 1 to 100 (100 by default).
after_id Optional ID of an object to fetch a page after (newest first).
before_id Optional ID of an object to fetch a page before (newest first).

Webhooks

You can create a webhook and set up a callback to get notified about certain events from Swipe.

Parameter Description
ATTRIBUTES
id Integer Webhook unique identifier.
event String Event to trigger webhook on.
url String Callback URL.

Create a webhook

POST https://swipe.lv/api/v0.5/webhooks/

You have to create a webhook to set up a callback about certain events in Swipe.

Parameter Description
ATTRIBUTES
event Required Event to trigger webhook on.
url Required Callback URL.

Update a webhook

PUT https://swipe.lv/api/v0.5/webhooks/<id>/

You can update a webhook using its id.

Parameter Description
ATTRIBUTES
event Required Event to trigger webhook on.
url Required Callback URL.

Delete a webhook

DELETE https://swipe.lv/api/v0.5/webhooks/<id>/

You can delete a webhook using its id.

Retrieve a webhook

GET https://swipe.lv/api/v0.5/webhooks/<id>/

You can retrieve a webhook using its id.

List all webhooks

GET https://swipe.lv/api/v0.5/webhooks/

You can retrieve a list of registered webhooks. This request supports pagination.

Example: ?limit=50&after_id=77

Parameter Description
ATTRIBUTES
limit Optional Number of objects per page, from 1 to 100 (100 by default).
after_id Optional ID of an object to fetch a page after (newest first).
before_id Optional ID of an object to fetch a page before (newest first).