NAV Navbar
Logo

- Quick guide -

Save a card

Save card details for future transactions.


Which programming language do you prefer?

| PHP | Python | .NET |

Use arrow keys or space bar to navigate in the presentation.

Installing the Library

1- Download the library on GitHub:

github.com/payplug/payplug-php

github.com/payplug/payplug-python

github.com/payplug/payplug-sharp

2- Add to all your pages that use the API:

<?php
require_once('PATH_TO_PAYPLUG/payplug_php/lib/init.php');
import payplug
using Payplug;

Authentication

Verify your identity when communicating with the API by providing a secret key in all your requests.

To submit your credentials, include your key in all pages that use the API:

<?php
\Payplug\Payplug::setSecretKey('sk_live_VOTRE_CLE_PRIVEE');
payplug.set_secret_key('sk_live_VOTRE_CLE_PRIVEE')
Configuration.SecretKey = "sk_live_VOTRE_CLE_PRIVEE";

API keys start with “sk_”.
They are available in My account, then API Credentials in the PayPlug portal.

Access LIVE and TEST modes using the same endpoint. To switch between modes, simply provide the related secret key to the mode you wish to access.

Using the “save card” feature

  1. Create the payment using save_card = true; a link to a payment page will be generated.
  2. Redirect the customer to the payment page.
  3. After entering card details, your customer is automatically redirected to the previously-indicated return page on your site.
  4. PayPlug sends you a confirmation including the secure card ID via IPN (Instant Payment Notification).

Combining the “save card” with a payment

The following is an example of a payment with the “save card” feature that automatically redirects your client to the payment page:

<?php
$email = 'john.watson@example.net';
$amount = 33;
$customer_id = '42710';

$payment = \Payplug\Payment::create(array(
  'amount'           => $amount * 100,
  'currency'         => 'EUR',
  'save_card'        => true,
  'customer'         => array(
    'email'          => $email
  ),
  'hosted_payment'   => array(
    'return_url'     => 'https://example.net/success?id='.$customer_id,
    'cancel_url'     => 'https://example.net/cancel?id='.$customer_id
  ),
  'notification_url' => 'https://example.net/notifications?id='.$customer_id,
  'metadata'         => array(
    'customer_id'    => $customer_id
  )
));
payment_data = {
  'amount': 3300,
  'currency': 'EUR',
  'save_card': True,
  'customer': {
    'email': 'john.watson@example.net'
  },
  'hosted_payment': {
    'return_url': 'https://example.net/success?id=42710',
    'cancel_url': 'https://example.net/cancel?id=42710',
  },
  'notification_url': 'https://example.net/notifications?id=42710',
  'metadata': {
    'customer_id': 42710,
  },
}
payment = payplug.Payment.create(**payment_data)
var paymentData = new Dictionary<string, dynamic>
{
  {"amount", 3300},
  {"currency", "EUR"},
  {"save_card", true},
  {"customer", new Dictionary<string, object>
    {
      {"email", "john.watson@example.net"}
    }
  },
  {"hosted_payment", new Dictionary<string, object>
    {
      {"return_url", "https://example.net/success?id=42710"},
      {"cancel_url", "https://example.net/cancel?id=42710"}
    }
  },
  {"notification_url", "https://example.net/notifications?id=42710"},
  {"metadata", new Dictionary<string, object>
    {
      {"customer_id", "42710"}
    }
  }

};
var payment = Payment.Create(paymentData);

All amounts must be expressed in centimes as positive whole numbers (1€ = 100 centimes).

Confirmation

When creating a payment, you can specify a notification URL for use with IPN: notification_url. Whether the payment is successful or fails, a POST query containing an object corresponding to the payment will be sent to your server.

<?php
$input = file_get_contents('php://input');
try {
  $resource = \Payplug\Notification::treat($input);
  if ($resource instanceof \Payplug\Resource\Payment && $resource->is_paid) {
    $payment_id = $resource->id;
    $payment_state = $resource->is_paid,true;
    $payment_date = $resource->hosted_payment->paid_at;
    $payment_amount = $resource->amount;
    if ($resource->save_card == true) {
      $card_id = $resource->card->id;
      $card_exp_month = $resource->card->exp_month;
      $card_exp_year = $resource->card->exp_year;
    }
    $payment_data = $resource->metadata[customer_id];
  }
}
catch (\Payplug\Exception\PayplugException $exception) {
    echo $exception;
}
request_body = request.body
try:
  resource = payplug.notifications.treat(request_body)
except payplug.exceptions.PayplugError:
  pass
else:
  if resource.object == 'payment' and resource.is_paid:
    payment_id = str(resource.id)
    payment_state = str(resource.is_paid)
    payment_date = datetime.datetime.fromtimestamp(resource.hosted_payment.paid_at).strftime('%d/%m/%Y %H:%M:%S')
    payment_amount = str(resource.amount)
    if resource.save_card == True
      card_id = str(resource.card.id)
      card_exp_month = str(resource.card.exp_month)
      card_exp_year = str(resource.card.exp_year)
      pass
    payment_data = resource.metadata['customer_id']
    pass
using Payplug.Exceptions;

string json = new StreamReader(request.InputStream).ReadToEnd();
try
{
  var payment = Notification.Treat(json);
  if (payment["object"] == "payment" && payment["is_paid"])
  {
    var payment_id = payment["id"];
    var payment_state = payment["is_paid"];
    var payment_date = DateTimeOffset.FromUnixTimeSeconds(payment["hosted_payment"]["paid_at"]).DateTime;
    var payment_amount = payment["amount"];
    if (payment["save_card"]) == true)
    {
      var card_id = payment["card"]["id"];
      var card_exp_month = payment["card"]["exp_month"];
      var card_exp_year = payment["card"]["exp_year"];
    }
    var payment_data = payment["metadata"]["customer_id"];
  }
}
catch (InvalidApiResourceException e)
{
  Console.WriteLine(e);
}

You may now extract the card ID from the object in the IPN. This is what you will use to initiate future transactions. We recommend that you also document the card’s expiration date in order to verify that the card is still valid before attempting future payments.

Payments using a card ID

  1. Create the payment using payment_method and the previously saved card ID.
  2. PayPlug sends you a confirmation via IPN.

Processing a payment using a card ID

Now that you have a card ID, you can initiate new payments without sending your customer to a payment page:

<?php
$email = 'john.watson@example.net';
$amount = 33;
$customer_id = '42710';
$card_id = 'card_e7133426b8de947b37161dfba1897dd1';

$payment = \Payplug\Payment::create(array(
  'amount'            => $amount * 100,
  'currency'          => 'EUR',
  'payment_method'    => $card_id,
  'customer'          => array(
      'email'             => $email
  ),
  'notification_url'  => 'https://example.net/notifications?id='.$customer_id,
  'metadata'          => array(
      'customer_id'       => $customer_id
));
payment_data = {
  'amount': 1000,
  'currency': 'EUR',
  'payment_method': 'card_e7133426b8de947b37161dfba1897dd1',
  'customer': {
    'email': 'john.watson@example.net'
  },
  'notification_url': 'https://example.net/notifications?id=42710',
  'metadata': {
    'customer_id': 42710,
  },
}
payment = payplug.Payment.create(**payment_data)
var paymentData = new Dictionary<string, dynamic>
{
  {"amount", 1000},
  {"currency", "EUR"},
  {"payment_method", "card_e7133426b8de947b37161dfba1897dd1"},
  {"customer", new Dictionary<string, object>
    {
      {"email", "john.watson@example.net"}
    }
  },

  {"notification_url", "https://example.net/notifications?id=42710"},
  {"metadata", new Dictionary<string, object>
    {
      {"customer_id", "42710"}
    }
  }
};
var payment = Payment.Create(paymentData);

Your customer will receive a confirmation email after each new transaction.

Advantages

The ‘save card’ feature makes the following payment options possible:

1-click ordering

Customers can pay securely without typing in their card details for every purchase.

Recurring payments

Customers can subscribe to services on your site using recurring payments.

Instalments

Customers can pay in three or four interest-free instalments (within a maximum 90-day period).

Please note that recurring payments and instalments are not automated; you will need to manage the payment schedules internally.

Links & Resources


[ Click to return to the beginning of presentation ]