Payment Automation Integration Guide

Learn how to automate your payments with ease and organize a convenient payout project to aid the cases when rendering large volume of payments on a regular, scheduled or one-time basis.

Table of contents:

§1. General Information

In this guide we will review practical examples, while general OKPAY automation features are described in the Programming Interfaces section of Comprehensive Manual.

OKPAY provides great functionality for payments automation billing – i.e. sending payments from your OKPAY account balance to other users and parties. You are also able to use available withdrawal options to create a convenient payout service and send funds to other parties.

Note: Payouts as well as API instruments are available to any verified OKPAY user who selected a Business account type. Read more in the General Reference Guide for Merchants.

Here are some of the Payments Automation features:

  • Enable automatic payouts and withdrawals for your business via API.
  • Send mass payments to users within OKPAY system.
  • Specify who will pay the fee for OKPAY internal transfer.
  • Supported payout/withdrawal methods include Credit Cards, Payment Systems as well as Cryptocurrencies.
  • Check transaction status and account balance at any moment.

§2. API Setup

API tools are available to verified OKPAY users. Before proceeding with further integration and API tools usage please enable API access for your OKPAY wallet. Detailed information can be found in API Setup section of the Comprehensive Manual.

§3. How to…

Please find below various examples of OKPAY automation implementation.

§3.1. Check Account

It is a good practice to check the receiver account status before sending money with OKPAY. The Account_Check API function allows you to check account existence by providing a Wallet ID, email address or a phone number.

Detail information can be found on the Account_Check Function page.

Note: The receiver may be unregistered, in this case you can still send the funds. Money will not be lost in any case. Receiver will get a payment notification email with the link to sign up and get the funds. Otherwise you can cancel pending transaction before it has been claimed by the receiver.

§3.2. Check Balance

Make sure your OKPAY account balance is sufficient before sending any payments. The Wallet_Get_Balance API function allows you to get the balance of all available currencies for a specified wallet.

Detail information can be found on the Wallet_Get_Balance Function page.

Additionally, if you need to check the balance of the specific currency on your wallet, please refer to the Wallet_Get_Currency_Balance API function.

Detail information can be found on the Wallet_Get_Currency_Balance Function page.

§3.3. Send Money

Once you have checked your wallet balance and the accounts of receivers you can can be sure that the money will be sent without any issues. The Send_Money function allows you to send money instantly with OKPAY e-currency to any other user by using the balance of your wallet. There are basically 3 main parameters that you need to specify for your payout, such us:

  • the receiver credentials (OKPAY Wallet ID or email address)
  • currency of the transfer (one of the supported by OKPAY currencies)
  • original amount of the transfer with two decimal places

Note: You can send money to any email address, if the client is not yet registered he will get a notification email about incoming transfer as well as the link to sign up for OKPAY and receive the money.

Once the operation is completed you receive a TxnInfo structure, including operation ID, date & time, status and other information.

OKPAY Web Interface also supports easy payouts by providing the Mass Payment operation with up to 100 internal transfers with one action, however same functionality without any limitations can be performed via API.

Figure 1. Mass Payment.

Alt1.

As per instructions you need to create a tab-delimited text file with the receiver and transaction details. Please note that there is a limit of 100 transactions per single file.

Figure 2. Mass Payment.

Alt2.

§3.4. Manage Payments

OKPAY provides all necessary tools to prepare and manage already sent payments.

§3.4.1. Get Transaction Information

Once the payments have been sent, you are able to instantly obtain information on the transfer, return values contain TxnInfo structure. Please find the additional information on the Transaction_Get function.

§3.4.2. Get Transaction History

If you need to view the transaction history of the specific wallet via API, you can use the Transaction_History function.

Depending on your requirements, transaction history can be generated in a specific manner, for example to find a payments of a particular user, set the parameters of search interval, transaction, etc.

§3.5. Payouts/Withdrawals

API for withdrawal in OKPAY is a very useful instrument that allows users not only withdraw funds from the OKPAY account but also use the available withdrawal methods for your payout project and send money to other parties.

§3.5.1. Make Credit Cards Payout/Withdrawal

Currently, OKPAY supports credit and debit cards payout in the RUB currency (Russia and CIS countries); Detailed information can be found on the Withdraw_To_Card_RU function page.

As well as USD/EUR currencies (other countries). Detailed information can be found on the Withdraw_To_Card_World function page.

While using this option you need to specify the card credentials and payment details. Upon completing the transaction a WithdrawalInfo structure is returned.

§3.5.2. Make Payment System Payout/Withdrawal

Apart from Credit Card withdrawal functionality, you can also withdraw funds from the OKPAY account or send money to another user via supported payment systems (for example Qiwi, W1 etc.). Detailed information can be found on the Withdraw_To_Ecurrency function page.

In this case you need to specify the payment system which will be used to send the funds (the payment system should be supported by OKPAY withdrawal API), account credentials, amount and the currency.

Upon completing the transaction a WithdrawalInfo structure is returned.

Note: Preliminarily, before sending the funds with the supported Payment System, you can calculate the commissions and fees associated with the transfer (thus find out the final amount that will be received) by using the Withdraw_To_Ecurrency_Calculate function:

This function calculates the commission for the selected payment options and amount, without making actual payment.

§3.5.3. Make Cryptocurrency Payout/Withdrawal

OKPAY also supports withdrawal to popular cryptocurrencies (bitcoin, litecoin, dogecoin) via the Withdraw_To_CryptoCurrency function. Detailed information can be found on the Withdraw_To_CryptoCurrency function page.

Specify the cryptocurrency type which will be used for withdrawal as well as payment details.

Note: Preliminarily, before sending the funds with the supported cryptocurrency, you can calculate the commissions and fees associated with the transfer (thus find out the final amount that will be received) by using the Withdraw_To_CryptoCurrency_Calculate function.

This function calculates the commission for the selected payment options and amount, without making actual payment.

§4. Code Samples in Various Programming Languages

For your reference, several examples of OKPAY API usage are provided in popular programming languages.

Sample in PHP
             <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  <html>
  <head>
  	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  	<title>OKPAY API PHP Test</title>
  </head>
 
  <body>
 
  <?php
  	ini_set("display_errors", 1);
  	echo "<h1>OKPAY API PHP Test</h1>\r\n\r\n";
  	try
  	{
  		$secWord  = "secretword"; // wallet API password
  		$WalletID = "OKxxxxxxxxx"; // wallet ID
 
  		$datePart = gmdate("Ymd");
  		$timePart = gmdate("H");
  		$authString = $secWord.":".$datePart.":".$timePart;
 
  		echo "<p>AuthString: ".$authString."</p>";
  		$sha256 = bin2hex(hash('sha256', $authString, true));
  		$secToken = strtoupper($sha256);
 
  		echo "<p>Security Token: ".$secToken."</p>";
 
 		// Connecting to SOAP
 		$opts = array(
 			'http'=>array(
 				'user_agent' => 'PHPSoapClient'
 			)
 		);
 		$context = stream_context_create($opts);
 		$client = new SoapClient("https://api.okpay.com/OkPayAPI?wsdl",
 									array(
 										'stream_context' => $context,
 										'cache_wsdl' => WSDL_CACHE_NONE)
 								);
 
  		echo "<pre>" . print_r($client->__getFunctions(), 1) . "</pre>";
 
  		echo "Get current server GMT Time (Get_Date_Time):<br />";
  		$webService = $client->Get_Date_Time();
  		$wsResult = $webService->Get_Date_TimeResult;
  		echo $wsResult ."<br />";
 
  		echo "Get Balance for EUR currency (Wallet_Get_Currency_Balance):<br />";
  		$obj->WalletID = $WalletID;
  		$obj->SecurityToken = $secToken;
  		$obj->Currency = "EUR";
  		$webService = $client->Wallet_Get_Currency_Balance($obj);
  		$wsResult = $webService->Wallet_Get_Currency_BalanceResult;
  		print_r($wsResult);
 
 
 		echo "Get All Balances for account (Wallet_Get_Balance):<br />";
  		$obj->WalletID = $WalletID;
  		$obj->SecurityToken = $secToken;
  		$webService = $client->Wallet_Get_Balance($obj);
  		$wsResult = $webService->Wallet_Get_BalanceResult;
  		print_r($wsResult);
 
 		echo "Money transfer EUR for username@gmail.com (Send_Money):<br />";
  		$obj->WalletID = $WalletID;
  		$obj->SecurityToken = $secToken;
  		$obj->Currency = "EUR";
  		$obj->Receiver = "username@gmail.com";
  		$obj->Amount = 0.01;
  		$obj->Comment = "PHP API Transfer";
  		$obj->IsReceiverPaysFees = FALSE;
  		$webService = $client->Send_Money($obj);
  		$wsResult = $webService->Send_MoneyResult;
  		print_r($wsResult);
 
 		echo "Get Transaction Info (Transaction_Get):<br />";
 		$obj->WalletID = $WalletID;
 		$obj->SecurityToken = $secToken;
 		$obj->TxnID = "123456789";
 		$webService = $client->Transaction_Get($obj);
 		$wsResult = $webService->Transaction_GetResult;
         print_r($wsResult);
 
  	}
  	catch (Exception $e)
  	{
  		print  "Caught exception: ".  $e->getMessage(). "\n";
  	}
  ?>
 </body>
 </html>
Sample in C#
             Add Service Reference to your C# project (https://api.okpay.com/OkPayAPI)
 
 class Program
  {
   static void Main(string[] args)
   {
    //API Access Information
    string codeword = "codeword";
    string walletID = "OKxxxxxxxxx";
    //Generating Security Token
    string securityToken = HashStringSHA256(codeword + DateTime.UtcNow.ToString(":yyyyMMdd:HH"));
 
    //Creating proxy client
    using (var proxy = new OkPayAPI.I_OkPayAPIClient())
    {
     //Get server time
     Console.WriteLine(proxy.Get_Date_Time());
 
     //Get Balance
     foreach (var item in proxy.Wallet_Get_Balance(walletID, securityToken))
     {
      Console.WriteLine(item.Currency + ": " + item.Amount.ToString("0.00"));
     }
 
 
 
     //Get Transaction Info
     var TI = proxy.Transaction_Get(walletID, securityToken, 123456789);
 
     Console.WriteLine(TI.OperationName + " " + TI.Amount.ToString("0.00") + TI.Currency);
 
 
     //Send Money
     var OI = proxy.Send_Money(walletID, securityToken, "test@okpay.com", "EUR", 0.02M, "My API Payment", true);
     Console.WriteLine("OperationID: " + OI.ToString());
 
 
    }
    Console.ReadLine();
   }
 
   //Calculating Hash
   static string HashStringSHA256(string Value)
   {
    System.Security.Cryptography.SHA256CryptoServiceProvider x = new System.Security.Cryptography.SHA256CryptoServiceProvider();
    byte[] data = System.Text.Encoding.ASCII.GetBytes(Value);
    data = x.ComputeHash(data);
    return BitConverter.ToString(data).Replace("-", "");
   }
  }
Sample in Visual Basic
            #SampleVB#
Sample in Perl
            #SamplePerl#
Sample in Java/JSP
            #SampleJava#
Sample in Python
             #!/usr/bin/env python
 # -*- encoding: utf-8 -*-
 
 from suds.client import Client
 from suds import WebFault
 import datetime
 from hashlib import sha256
 
 
 class OkPayAPI():
 
     def __init__(self, api_password=None, wallet_id=None):
         ''' Set up your API Access Information
             https://www.okpay.com/en/developers/interfaces/setup.html '''
         if api_password == None:
             self.api_password = "your details here"
         else:
             self.api_password = api_password
         if wallet_id == None:
             self.wallet_id = "your details here"
         else:
             self.wallet_id = wallet_id
 
         #Generate Security Token
         concatenated = api_password + datetime.datetime.utcnow().strftime(":%Y%m%d:%H")
         self.security_token = sha256(concatenated).hexdigest()
         #Create proxy client
         self.client = Client('https://api.okpay.com/OkPayAPI?singleWsdl')
 
     def get_date_time(self):
         ''' Get the server time in UTC.
             Params: None
             Returns: String value - Date (YYYY-MM-DD HH:mm:SS)
                     2010-12-31 10:33:44 '''
         return self.client.service.Get_Date_Time()
 
     def get_balance(self, currency=None):
         ''' Get the balance of all currency wallets or of a single currency.
             Params: currency is a three-letter code from the list at
                         https://www.okpay.com/en/developers/currency-codes.html
                         if no currency is passed then all wallet balances are
                         returned.
             Returns: dictionary in the form {'balance': {'CUR': '0.0', ...}} '''
         try:
             if not currency == None:
                 response = self.client.service.Wallet_Get_Currency_Balance(
                             self.wallet_id, self.security_token,
                             currency)
                 balance = {response.Currency: response.Amount}
             else:
                 response = self.client.service.Wallet_Get_Balance(
                         self.wallet_id, self.security_token)
                 balance = {item.Currency: item.Amount for item in response.Balance}
             response = {'success': 1, 'balance': balance}
         except WebFault, e:
             response = {'success': 0, 'error': e}
 
         return response
OKPAY RSS
OKPAY Forum
OKPAY on Facebook
OKPAY on Livejournal
OKPAY on Twitter
OKPAY on VK
OKPAY on Linkedin
OKPAY on Youtube