Recurring Payments (Subscriptions) - Subsequent (MIT)

The following guide, describes how you will be able to make server to server payments using an existing mandate

POST Request

All you need to do is to pass the customer token, with the mandate that you received after the Initial Transaction.

POST Request with a Payload that includes the 'token="cus_xxxxxxxxxxxxxxxxxxx"', 'amount', 'secret-key' 'mandate*' Everypay's payments API.

Here are some examples:

<?php
$pk = 'your-private-key'
$postRequest = array(
    'token' => 'cus_xxxxxxxxxxxxxxxxxxx',
    'amount' => '10000',
    'description' => 'Order No.123',
    'mandate' => 'man_xxxxxxxxxxxxxxxxxxx',
);

$cURLConnection = curl_init('https://api.everypay.gr/payments');
curl_setopt($cURLConnection, CURLOPT_USERPWD, $pk:);
curl_setopt($cURLConnection, CURLOPT_POSTFIELDS, $postRequest);
curl_setopt($cURLConnection, CURLOPT_RETURNTRANSFER, true);

$apiResponse = curl_exec($cURLConnection);
curl_close($cURLConnection);

// $apiResponse - available data from the API request
$jsonArrayResponse = json_decode($apiResponse);
require 'net/http'
require 'uri'

uri = URI.parse("https://api.everypay.gr/payments")
request = Net::HTTP::Post.new(uri)
request.basic_auth("your-secret-key", "")
request.body = "token=cus_xxxxxxxxxxxxxxxxxxx&amount=1000&description=Order #GGA-435167&mandate=man_xxxxxxxxxxxxxxxxxxx"

req_options = {
  use_ssl: uri.scheme == "https",
}

response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
  http.request(request)
end

# response.code
# response.body
import requests

data = {
  'token': 'cus_xxxxxxxxxxxxxxxxxxx',
  'amount': '1000',
  'description': 'Order #GGA-435167',
  'mandate': 'man_xxxxxxxxxxxxxxxxxxx'
}

response = requests.post('https://api.everypay.gr/payments', data=data, auth=('your-secret-key', ''))
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import org.apache.commons.codec.binary.Base64;


public class HttpBasicAuth {

    public static void main(String[] args) {

        try {
            URL url = new URL ("https://api.everypay.gr/payments");

            Base64 b = new Base64();
            String encoding = b.encodeAsString(new String("your-secret-key:").getBytes());
            
            String urlParameters  = "token=cus_xxxxxxxxxxxxxxxxxxx&amount=1000&description=Order1&mandate=man_xxxxxxxxxxxxxxxxxxx";
            byte[] postData = urlParameters.getBytes( StandardCharsets.UTF_8 );

            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("POST");
            connection.setDoOutput(true);
            connection.setRequestProperty  ("Authorization", "Basic " + encoding);
            connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 
            connection.setRequestProperty("charset", "utf-8");
            
            try(DataOutputStream wr = new DataOutputStream(connection.getOutputStream())) {
                wr.write( postData );
            }
            InputStream content = (InputStream)connection.getInputStream();
            BufferedReader in   = 
                new BufferedReader (new InputStreamReader (content));
            String line;
            while ((line = in.readLine()) != null) {
                System.out.println(line);
            }
        } 
        catch(Exception e) {
            e.printStackTrace();
        }
    }
}
const https = require('https')
const querystring = require('querystring');

const form = querystring.stringify({
  token: 'cus_xxxxxxxxxxxxxxxxxxx',
  amount: '10000',
  description: 'Order No.123',
  mandate: 'man_xxxxxxxxxxxxxxxxxxx'
});

const auth = 'Basic ' + new Buffer("{your-private-key}:").toString('base64');

const options = {
  hostname: 'api.everypay.gr',
  path: '/payments',
  method: 'POST',
  headers: {
    "Proxy-Authorization": auth,
    'Content-Type': 'application/x-www-form-urlencoded',
  }
}

const req = https.request(options, res => {
  console.log(`statusCode: ${res.statusCode}`)

  res.on('data', d => {
    console.log('response', d);
  })
})

req.on('error', error => {
  console.error(error)
})

req.write(form)
req.end()
using (var httpClient = new HttpClient())
{
  using (var request = new HttpRequestMessage(new HttpMethod("POST"), "https://api.everypay.gr/payments"))
  {
    var base64authorization = Convert.ToBase64String(Encoding.ASCII.GetBytes("sk_xxxxxxxxxxxxxxxxxxx:"));
    request.Headers.TryAddWithoutValidation("Authorization", $"Basic {base64authorization}"); 

    var contentList = new List<string>();
    contentList.Add("token=cus_xxxxxxxxxxxxxxxxxxx");
    contentList.Add("amount=1000");
    contentList.Add("description=Order #GGA-435167");
    contentList.Add("mandate=man_xxxxxxxxxxxxxxxxxxx");
    request.Content = new StringContent(string.Join("&", contentList));
    request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/x-www-form-urlencoded"); 

    var response = await httpClient.SendAsync(request);
  }
}

This request must be server to server, as it contains your secret-key. You should never expose your secret-key client-side.

If the response is successful, it means that the payment has gone through, and the card has been successfully charged.

If there is an issue in the response, and it keeps happening then it means that you need to inform your customer that he needs to recreate the initial payment, and you need to store a new mandate.

We suggest that you keep the responses, attached to that specific transaction in your database.