API Details
What is the API?
The VirtaPay API (Application Programming Interface) provides a simple way for websites and web-based services to integrate VirtaPay payments. Here are a few examples of services that may benefit from using the API...
  • GPT websites... also known as "get-paid-to". These sites could pay their members automatically in VP$ for performing tasks online. Examples may include reading email, filling out surveys, visiting websites, etc.
  • Currency exchanges. We plan to remove the restriction on currency exchanges and allow the open exchange of VP$ into and out of any other currency, virtual or physical. We expect there will be several services that come online using the API to provide currency exchange.
  • Marketplaces. Classified ads, auctions, etc. We expect some people will surely use the API to create web services allowing people to buy and sell items using VP$. We will remove the restriction on physical items, so these marketplaces may allow you to buy and sell items both digital and physical.
  • Mobile payment apps. Some developers may choose to create mobile payment apps that allow you to easily send VirtaPay payments with your mobile phone. This could make it more attractive for local sellers to accept VP$ as payment.
  • In-game currency. The API will allow online game developers to use VP$ as a currency in their games. This could allow users to earn VP$ within a game and spend it to buy items within the game.
REST
The VirtaPay API is designed to use a REST interface. If you are not already familiar REST, you can learn more by reading the dissertation by Roy Fielding (who introduced the REST concept). You can get a basic overview of REST in the Wikipedia article: Representational State Transfer
API Version
The current version of the VirtaPay API is: 1.0. The version number is part of the URL used to access the API services. This makes it easy to see which version of the API you are attempting to access. It also allows VirtaPay to change or upgrade the API in new versions without affecting applications still using older versions of the API.
In addition to the current version, VirtaPay will always keep the three most recent versions of the API accessible. For example, when the API reaches version 4.0, everything down to version 1.0 will still work. However, when the API reaches version 5.0, everything below 2.0 will be retired.
What Clients can Access the API?
The API can be accessed with any HTTP-based client that can pass properly formatted REST requests. It makes no difference to the API whether you use .NET, PHP, Java, Python, Ruby, etc.
Although VirtaPay does not endorse any particular REST tools for development, you may find RESTClient to be helpful while developing and testing RESTful web services.
Request Header
The VirtaPay API requires that you send an "Authorization" header with all service requests that access your account (get account balance, send payment, transaction details, etc.). The API will return a 403 [Forbidden] status code if you attempt any action on your account without using your API key.
Need an API key? Log in and click "API" in the footer links.
To use your API key in a REST request, you must include the full API key in the header of the request. It must be included using the Authorization header parameter. Here's an example of what that header might look like:
Authorization: USERNAME-AB12CD34EF56AB12CD34EF56AB12CD34AB12CD34
Note: You must replace the above (USERNAME-AB12...) with your own API key.
Output
The VirtaPay API will output results in the JSON format. The API does not support XML, CSV or any other type of output. If you are not familiar with JSON, you may want to read the Wikipedia article: JSON. You will also want to make sure you understand how to parse the JSON output with the client you use to access the API. As an example, if your web service is built using PHP, you could simply use the built-in PHP function: json_decode().
API Service Description
A full service description for the VirtaPay API Version 1.0 including the following methods: (balance, payment, transaction) is available here: [ https://www.virtapay.com/api/1.0 ].
Code Samples
The following code samples are in PHP. However, please remember, the API can be accessed with any HTTP-based client that can pass properly formatted REST requests, including .NET, PHP, Java, Python, Ruby, etc. Even if you don't code in PHP, have a look over the simple examples below to get an idea of how to access the API using the language of your choice.
Note: In order for the code samples to work, you must replace the text contained between the hash markers (##) below as indicated and completely remove the hash markers.
Sample code to GET account balance using the API...
<?php

$sendHeaders = array(
  "Accept: application/json", 
  "Authorization: ##API-KEY-GOES-HERE##"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.virtapay.com/api/1.0/balance");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $sendHeaders);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

# store the JSON response in $response 
$response = curl_exec($ch);

# store the HTTP header response code in $httpCode
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

echo 'The HTTP status code was: '.$httpCode;
echo '<br><br>';
echo $response;

?>
    
Sample code to POST a payment using the API...
<?php

$sendHeaders = array(
  "Accept: application/json", 
  "Authorization: ##API-KEY-GOES-HERE##"
);
$params = array (
  'to' => '##username-to-pay-goes-here##',
  'amount' => '##amount-to-pay-goes-here##',
  'memo' => '##memo-goes-here##'
);
$postVars = http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.virtapay.com/api/1.0/payment");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postVars);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $sendHeaders);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

# store the JSON response in $response 
$response = curl_exec($ch);

# store the HTTP header response code in $httpCode
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

echo 'The HTTP status code was: '.$httpCode;
echo '<br><br>';
echo $response;

?>
    
Sample code to GET transaction details using the API...
<?php

$sendHeaders = array(
  "Accept: application/json", 
  "Authorization: ##API-KEY-GOES-HERE##"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.virtapay.com/api/1.0/transaction/##TRANSACTION-ID-GOES-HERE##");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $sendHeaders);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

# store the JSON response in $response 
$response = curl_exec($ch);

# store the HTTP header response code in $httpCode
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

echo 'The HTTP status code was: '.$httpCode;
echo '<br><br>';
echo $response;

?>
    
Secure areas of VirtaPay Secured by Comodo
Terms of Service | Privacy Policy | Anti-Spam Policy | API | Blog
© 2014 VirtaPay. All rights reserved.