PHPackages                             arthurnumen/veritrans-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. arthurnumen/veritrans-php

ActiveLibrary

arthurnumen/veritrans-php
=========================

PHP Wraper for Veritrans VT-Web Payment API.

1.0.1(10y ago)03.9k↓100%2[1 PRs](https://github.com/arthurnumen/veritrans-php/pulls)GPL-3.0PHPPHP &gt;=5.3.0

Since Nov 3Pushed 7y agoCompare

[ Source](https://github.com/arthurnumen/veritrans-php)[ Packagist](https://packagist.org/packages/arthurnumen/veritrans-php)[ Docs](https://veritrans.co.id)[ RSS](/packages/arthurnumen-veritrans-php/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (7)Used By (0)

Veritrans-PHP
=============

[](#veritrans-php)

[![Build Status](https://camo.githubusercontent.com/f588c86dc1c081d114c37da473bb40958ce8ad2d76cdbf088e7593ebdb0fb29f/68747470733a2f2f7472617669732d63692e6f72672f766572697472616e732f766572697472616e732d7068702e737667)](https://travis-ci.org/veritrans/veritrans-php)

Veritrans ❤️ PHP!

This is the all new PHP client library for Veritrans 2.0. This is the official PHP wrapper for Veritrans Payment API. Visit  for more information about the product and see documentation at  for more technical details.

Installation
------------

[](#installation)

### Composer Installation

[](#composer-installation)

If you are using [Composer](https://getcomposer.org), add this require line to your `composer.json` file:

```
{
	"require": {
		"veritrans/veritrans-php": "dev-master"
	}
}
```

and run `composer install` on your terminal.

### Manual Instalation

[](#manual-instalation)

If you are not using Composer, you can clone or [download](https://github.com/veritrans/veritrans-php/archive/master.zip) this repository.

How to Use
----------

[](#how-to-use)

### General Settings

[](#general-settings)

#### Set Server Key

[](#set-server-key)

```
Veritrans_Config::$serverKey = '';
```

#### Set Client Key (VT-Direct)

[](#set-client-key-vt-direct)

```
Veritrans.client_key = "";
```

#### Set Environment

[](#set-environment)

```
// Development Environment (the default)
Veritrans_Config::$isProduction = false;

// Production Environment
Veritrans_Config::$isProduction = true;
```

#### Set Sanitization

[](#set-sanitization)

```
// Set sanitization off (default)
Veritrans_Config::$isSanitized = false;

// Set sanitization on
Veritrans_Config::$isSanitized = true;
```

### VT-Web

[](#vt-web)

You can see some VT-Web examples [here](https://github.com/veritrans/veritrans-php/tree/master/examples/vt-web).

#### Get Redirection URL of a Charge

[](#get-redirection-url-of-a-charge)

```
$params = array(
    'transaction_details' => array(
      'order_id' => rand(),
      'gross_amount' => 10000,
    ),
    'vtweb' => array()
  );

try {
  // Redirect to Veritrans VTWeb page
  header('Location: ' . Veritrans_Vtweb::getRedirectionUrl($params));
}
catch (Exception $e) {
  echo $e->getMessage();
}
```

#### Handle Notification Callback

[](#handle-notification-callback)

```
$notif = new Veritrans_Notification();

$transaction = $notif->transaction_status;
$fraud = $notif->fraud_status;

error_log("Order ID $notif->order_id: "."transaction status = $transaction, fraud staus = $fraud");

  if ($transaction == 'capture') {
    if ($fraud == 'challenge') {
      // TODO Set payment status in merchant's database to 'challenge'
    }
    else if ($fraud == 'accept') {
      // TODO Set payment status in merchant's database to 'success'
    }
  }
  else if ($transaction == 'cancel') {
    if ($fraud == 'challenge') {
      // TODO Set payment status in merchant's database to 'failure'
    }
    else if ($fraud == 'accept') {
      // TODO Set payment status in merchant's database to 'failure'
    }
  }
  else if ($transaction == 'deny') {
      // TODO Set payment status in merchant's database to 'failure'
  }
}
```

### VT-Direct

[](#vt-direct)

You can see some VT-Direct examples [here](https://github.com/veritrans/veritrans-php/tree/master/examples/vt-direct).

#### Checkout Page

[](#checkout-page)

```

  Checkout

  Checkout

      Checkout

        Card Number

        Expiration (MM/YYYY)

         /

        CVV

        Save credit card

      Submit Payment

    $(function () {
      // Sandbox URL
      Veritrans.url = "https://api.sandbox.veritrans.co.id/v2/token";
      // TODO: Change with your client key.
      Veritrans.client_key = "";
      var card = function () {
        return {
          "card_number": $(".card-number").val(),
          "card_exp_month": $(".card-expiry-month").val(),
          "card_exp_year": $(".card-expiry-year").val(),
          "card_cvv": $(".card-cvv").val(),
          "secure": false,
          "gross_amount": 200000
        }
      };

      function callback(response) {
        console.log(response);
        if (response.redirect_url) {
          console.log("3D SECURE");
          // 3D Secure transaction, please open this popup
          openDialog(response.redirect_url);

        }
        else if (response.status_code == "200") {
          console.log("NOT 3-D SECURE");
          // Success 3-D Secure or success normal
          closeDialog();
          // Submit form
          $("#token_id").val(response.token_id);
          $("#payment-form").submit();
        }
        else {
          // Failed request token
          console.log(response.status_code);
          alert(response.status_message);
        }
      }

      function openDialog(url) {
        $.fancybox.open({
          href: url,
          type: "iframe",
          autoSize: false,
          width: 700,
          height: 500,
          closeBtn: false,
          modal: true
        });
      }

      function closeDialog() {
        $.fancybox.close();
      }

      $(".submit-button").click(function (event) {
        console.log("SUBMIT");
        event.preventDefault();
        $(this).attr("disabled", "disabled");
        Veritrans.token(card, callback);
        return false;
      });
    });

```

#### Checkout Process

[](#checkout-process)

##### 1. Create Transaction Details

[](#1-create-transaction-details)

```
$transaction_details = array(
  'order_id'    => time(),
  'gross_amount'  => 200000
);
```

##### 2. Create Item Details, Billing Address, Shipping Address, and Customer Details (Optional)

[](#2-create-item-details-billing-address-shipping-address-and-customer-details-optional)

```
// Populate items
$items = array(
    array(
      'id'       => 'item1',
      'price'    => 100000,
      'quantity' => 1,
      'name'     => 'Adidas f50'
    ),
    array(
      'id'       => 'item2',
      'price'    => 50000,
      'quantity' => 2,
      'name'     => 'Nike N90'
    ));

// Populate customer's billing address
$billing_address = array(
    'first_name'   => "Andri",
    'last_name'    => "Setiawan",
    'address'      => "Karet Belakang 15A, Setiabudi.",
    'city'         => "Jakarta",
    'postal_code'  => "51161",
    'phone'        => "081322311801",
    'country_code' => 'IDN'
  );

// Populate customer's shipping address
$shipping_address = array(
    'first_name'   => "John",
    'last_name'    => "Watson",
    'address'      => "Bakerstreet 221B.",
    'city'         => "Jakarta",
    'postal_code'  => "51162",
    'phone'        => "081322311801",
    'country_code' => 'IDN'
  );

// Populate customer's info
$customer_details = array(
    'first_name'       => "Andri",
    'last_name'        => "Setiawan",
    'email'            => "test@test.com",
    'phone'            => "081322311801",
    'billing_address'  => $billing_address,
    'shipping_address' => $shipping_address
  );
```

##### 3. Get Token ID from Checkout Page

[](#3-get-token-id-from-checkout-page)

```
// Token ID from checkout page
$token_id = $_POST['token_id'];
```

##### 4. Create Transaction Data

[](#4-create-transaction-data)

```
// Transaction data to be sent
$transaction_data = array(
    'payment_type' => 'credit_card',
    'credit_card'  => array(
      'token_id'      => $token_id,
      'bank'          => 'bni',
      'save_token_id' => isset($_POST['save_cc'])
    ),
    'transaction_details' => $transaction_details,
    'item_details'        => $items,
    'customer_details'    => $customer_details
  );
```

##### 5. Charge

[](#5-charge)

```
$response = Veritrans_VtDirect::charge($transaction_data);
```

##### 6. Handle Transaction Status

[](#6-handle-transaction-status)

```
// Success
if($response->transaction_status == 'capture') {
  echo "Transaksi berhasil.";
  echo "Status transaksi untuk order id $response->order_id: " .
      "$response->transaction_status";

  echo "Detail transaksi:";
  echo "";
  var_dump($response);
  echo "";
}
// Deny
else if($response->transaction_status == 'deny') {
  echo "Transaksi ditolak.";
  echo "Status transaksi untuk order id .$response->order_id: " .
      "$response->transaction_status";

  echo "Detail transaksi:";
  echo "";
  var_dump($response);
  echo "";
}
// Challenge
else if($response->transaction_status == 'challenge') {
  echo "Transaksi challenge.";
  echo "Status transaksi untuk order id $response->order_id: " .
      "$response->transaction_status";

  echo "Detail transaksi:";
  echo "";
  var_dump($response);
  echo "";
}
// Error
else {
  echo "Terjadi kesalahan pada data transaksi yang dikirim.";
  echo "Status message: [$response->status_code] " .
      "$response->status_message";

  echo "";
  var_dump($response);
  echo "";
}
```

#### Process Transaction

[](#process-transaction)

##### Get a Transaction Status

[](#get-a-transaction-status)

```
$status = Veritrans_Transaction::status($orderId);
var_dump($status);
```

##### Approve a Transaction

[](#approve-a-transaction)

```
$approve = Veritrans_Transaction::approve($orderId);
var_dump($approve);
```

##### Cancel a Transaction

[](#cancel-a-transaction)

```
$cancel = Veritrans_Transaction::cancel($orderId);
var_dump($cancel);
```

Contributing
------------

[](#contributing)

### Developing e-commerce plug-ins

[](#developing-e-commerce-plug-ins)

There are several guides that must be taken care of when you develop new plugins.

1. **Handling currency other than IDR.** Veritrans `v1` and `v2` currently accepts payments in Indonesian Rupiah only. As a corrolary, there is a validation on the server to check whether the item prices are in integer or not. As much as you are tempted to round-off the price, DO NOT do that! Always prepare when your system uses currencies other than IDR, convert them to IDR accordingly, and only round the price AFTER that.
2. Consider using the **auto-sanitization** feature.

###  Health Score

32

—

LowBetter than 74% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor3

3 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~87 days

Total

2

Last Release

3986d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/362518a18b24ef56e9869f2c268c66024410998aefcb338ae614414e6e179170?d=identicon)[arthurnumen](/maintainers/arthurnumen)

---

Top Contributors

[![Paxa](https://avatars.githubusercontent.com/u/26019?v=4)](https://github.com/Paxa "Paxa (21 commits)")[![danieljl](https://avatars.githubusercontent.com/u/1947204?v=4)](https://github.com/danieljl "danieljl (17 commits)")[![robeth](https://avatars.githubusercontent.com/u/1451171?v=4)](https://github.com/robeth "robeth (14 commits)")[![yocki-s](https://avatars.githubusercontent.com/u/6572247?v=4)](https://github.com/yocki-s "yocki-s (12 commits)")[![harrypujianto](https://avatars.githubusercontent.com/u/9349240?v=4)](https://github.com/harrypujianto "harrypujianto (10 commits)")[![ismailfaruqi](https://avatars.githubusercontent.com/u/1243576?v=4)](https://github.com/ismailfaruqi "ismailfaruqi (9 commits)")[![arthurnumen](https://avatars.githubusercontent.com/u/2500565?v=4)](https://github.com/arthurnumen "arthurnumen (7 commits)")[![niteshpawar](https://avatars.githubusercontent.com/u/1705764?v=4)](https://github.com/niteshpawar "niteshpawar (3 commits)")[![mul14](https://avatars.githubusercontent.com/u/113989?v=4)](https://github.com/mul14 "mul14 (2 commits)")[![wendy0402](https://avatars.githubusercontent.com/u/4647969?v=4)](https://github.com/wendy0402 "wendy0402 (2 commits)")[![alvinlitani](https://avatars.githubusercontent.com/u/5961507?v=4)](https://github.com/alvinlitani "alvinlitani (2 commits)")[![adisetiawan](https://avatars.githubusercontent.com/u/73311?v=4)](https://github.com/adisetiawan "adisetiawan (1 commits)")[![rizdaprasetya](https://avatars.githubusercontent.com/u/13027142?v=4)](https://github.com/rizdaprasetya "rizdaprasetya (1 commits)")[![shaddiqa](https://avatars.githubusercontent.com/u/3852646?v=4)](https://github.com/shaddiqa "shaddiqa (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/arthurnumen-veritrans-php/health.svg)

```
[![Health](https://phpackages.com/badges/arthurnumen-veritrans-php/health.svg)](https://phpackages.com/packages/arthurnumen-veritrans-php)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
