Create a payment link

**POST**https://api.okepay.info/v1.0/Invoice/

PHPPythonBash
<?php
// $instanceName is a part of the url where you access your okepay installation.
// https://{$instanceName}.okepay.info
$instanceName = 'INSTANCE_NAME';

// $secret is the okepay secret for the communication between the applications
// if you think someone got your secret, just regenerate it in the okepay administration
$secret = 'INSTANCE_API_SECRET';

$okepay = new \Okepay\Okepay($instanceName, $secret);

// init empty request object
$invoice = new \Okepay\Models\Request\Invoice();

// info for payment link (reference id)
$invoice->setReferenceId('Order number of my online shop application');

// info for payment page (title, description)
$invoice->setTitle('Online shop payment');
$invoice->setDescription('Thanks for using Okepay to pay your order');

// administrative information, which provider to use (psp)
// psp #1 = Okepay' test mode, see https://okepay.biz/docs/miscellaneous
$invoice->setPsp(1);

// internal data only displayed to administrator
$invoice->setName('Online-Shop payment #001');

// payment information
$invoice->setPurpose('Shop Order #001');
$amount = 5.90;
// don't forget to multiply by 100
$invoice->setAmount($amount * 100);
// ISO code of currency, list of alternatives can be found here
// https://okepay.biz/docs/miscellaneous
$invoice->setCurrency('CHF');

// whether charge payment manually at a later date (type authorization)
$invoice->setPreAuthorization(false);

// whether charge payment manually at a later date (type reservation)
$invoice->setReservation(false);

// subscription information if you want the customer to authorize a recurring payment
// NOTE: This functionality is currently only available by using PAYMILL as a payment service provider. This also does not work in combination with pre-authorization payments.
//$invoice->setSubscriptionState(true);
//$invoice->setSubscriptionInterval('P1M');
//$invoice->setSubscriptionPeriod('P1Y');
//$invoice->setSubscriptionCancellationInterval('P3M');

// add contact information fields which should be filled by customer
// it would be great to provide at least an email address field
$invoice->addField($type = 'email', $mandatory = true, $defaultValue = 'my-customer@example.biz');
$invoice->addField($type = 'company', $mandatory = true, $defaultValue = 'Ueli Kramer Firma');
$invoice->addField($type = 'forename', $mandatory = true, $defaultValue = 'Ueli');
$invoice->addField($type = 'surname', $mandatory = true, $defaultValue = 'Kramer');
$invoice->addField($type = 'country', $mandatory = true, $defaultValue = 'AT');
$invoice->addField($type = 'title', $mandatory = true, $defaultValue = 'miss');
$invoice->addField($type = 'terms', $mandatory = true);
$invoice->addField($type = 'custom_field_1', $mandatory = true, $defaultValue = 'Value 001', $name = 'Das ist ein Feld');

// fire request with created and filled link request-object.
try {
    $response = $okepay->create($invoice);
    var_dump($response);
} catch (\Okepay\OkepayException $e) {
    print $e->getMessage();
}

 

import urllib.request
import hmac
import hashlib
import base64
import json

post_data = {
    "title": "test",
    "description": "test",
    "psp": 1,
    "referenceId": "test",
    "purpose": "test",
    "amount": 200,
    "currency": "CHF",
    "preAuthorization": 0,
    "reservation": 0,
}

data = urllib.parse.urlencode(post_data).encode('UTF-8')

dig = hmac.new(b'INSTANCE_API_SECRET', msg=data, digestmod=hashlib.sha256).digest()
post_data['ApiSignature'] = base64.b64encode(dig).decode()

data = urllib.parse.urlencode(post_data).encode('UTF-8')

result = urllib.request.urlopen('https://api.okepay.info/v1.0/Invoice/?instance=INSTANCE_NAME', data)
content = result.read().decode('UTF-8')
response = json.loads(content)
invoice = response['data'][0]
print(invoice)

 

apiSignature=`echo -n "title=Test&description=Testdescription&psp=1&referenceId=test&purpose=This+is+a+test&amount=200&currency=CHF&preAuthorization=0&reservation=0" | openssl dgst -sha256 -hmac "INSTANCE_API_SECRET" -binary | openssl enc -base64`
curl --request POST "https://api.okepay.info/v1.0/Invoice/?instance=INSTANCE_NAME" \
  --data-urlencode "title=Test" \
  --data-urlencode "description=Testdescription" \
  --data-urlencode "psp=1" \
  --data-urlencode "referenceId=test" \
  --data-urlencode "purpose=This is a test" \
  --data-urlencode "amount=200" \
  --data-urlencode "currency=CHF" \
  --data-urlencode "preAuthorization=0" \
  --data-urlencode "reservation=0" \
  --data-urlencode "ApiSignature=$apiSignature"

 

QUERY PARAMS  
instance
string
REQUIRED
Your OkePay instance name
BODY PARAMS  
title
string
REQUIRED
This is the page title which will be shown on the payment page
description
string
REQUIRED
This is a description which will be shown on the payment page.
psp
mixed type
REQUIRED
The psp which should be used for the payment. (Can be an array of integers.)
referenceId
string
REQUIRED
An internal reference id used by your system
purpose
string
REQUIRED
The purpose of the payment.
amount
int32
REQUIRED
The amount of the payments in cents.
currency
string
REQUIRED
The currency of the payments.
preAuthorization
boolean
Wheter charge payment manually at a later date (type authorization)
reservation
boolean
Whether charge payment manually at a later date (type reservation)
name
string
This is an internal name of the payment page. This name will be displayed to the administrator only.
fields
array of strings
The contact data fields which should be displayed. See fields for more

hideFields

boolean

 

Hide the whole contact fields section on invoice page

concardisOrderId

string

 

Only available for Concardis PSP and if the custom ORDERID option is activated in PSP settings OkePay administration. This ORDERID will be transferred to the Payengine.

Use invoice with modal box

To connect the created invoice with the payment (transaction), you must use the <> provided in the response from POST as <> of your modal box markup or build it yourself from the also provided hash.

Using the <> for that purpose will not work as expected, even when the demo results suggest that in some vague way.

Connecting your application with our OkePay payment

IF you have set up a webshop and would like to integrate OkePay as your payment solution then it is necessary for you to create an invoice in the OkePay system which you can then display as a payment form to the customer.