Giter Site home page Giter Site logo

veritrans-php-v1's Introduction

Veritrans Weblink Type PHP integration library

How to use

###STEP 1 : Requesting key

Given you already have cart ready for checkout. We create a veritrans instance

$veritrans = new Veritrans;
$veritrans->settlement_type = '01';
$veritrans->merchant_id = 'T100000000000001000001';
$veritrans->merchant_hash_key = '305e0328a366cbce8e17a385435bb7eb3f0cbcfbfc0f1c3ef56b658';
$veritrans->order_id = 'your_unique_order_id';
$veritrans->session_id = 'your_application_session_id';
$veritrans->gross_amount = '150000';
$veritrans->card_capture_flag = '1';
$veritrans->billing_address_different_with_shipping_address = 1;
$veritrans->required_shipping_address = 0;

dont forget to set your commodity

$commodities =  array (
						array("COMMODITY_ID" => 'sku1', "COMMODITY_PRICE" => '10000', 
							  "COMMODITY_QTY" => '2', 
						      "COMMODITY_NAME1" => 'Kaos', "COMMODITY_NAME2" => 'T-Shirt'),
						array("COMMODITY_ID" => 'sku2', "COMMODITY_PRICE" => '20000', 
							  "COMMODITY_QTY" => '1', 
						      "COMMODITY_NAME1" => 'Celana', "COMMODITY_NAME2" => 'Pants')
						);
						
$veritrans->commodity = $commodities;

request for a key

$key = $veritrans->get_keys();

save order infomation and keys to your database

$data = array(
  'order_id'    => $order_id,
  'session_id'  => $this->session->userdata('session_id'),
  'amount'      => $this->cart->total(),
  'token_browser' => $key['token_browser'],
  'token_merchant'=> $key['token_merchant']
);

In this sample, we're assuming that we use CodeIgniter ActiveRecord

$this->db->insert('orders', $data);

###STEP 2 : Redirect user to Veritrans payment page

Prepare the FORM to redirect the customer

<html>
<head>
	<title>Redirecting to Veritrans</title>
</head>
<body>	
	<form action="<?= Veritrans::PAYMENT_REDIRECT_URL ?>" method="post" id='form'  onSubmit="document.getElementById('submitBtn').disabled=true;">
  	<input type="hidden" name="MERCHANT_ID" value="<?= $merchant_id ?>" />
  	<input type="hidden" name="ORDER_ID" value="<?= $order['order_id'] ?>" />
  	<input type="hidden" name="TOKEN_BROWSER" value="<?= $key['token_browser'] ?>" />
  	<input id="submitBtn" type="submit" value="Confirm Checkout" />
	</form>
	
	<script language="javascript" type="text/javascript">
		  window.onload = function() {
		    document.getElementById("form").submit();
		  }
	</script>	
	
</body>
</html>

###STEP 3 : Responding Veritrans Payment Notification After the payment is completed Veritrans will contact Merchant's web server As Merchant, you need to response this query @TODO Validate request from veritrans, make sure it comes from veritrans not from hacker

Create Veritrans Notification instance

$veritrans_notification = new VeritransNotification();

Check if valid

if($order->token_merchant != $veritrans_notification->TOKEN_MERCHANT){
  echo "ERR";
  $this->db->insert('payment_notifications', array("params" => 'no match'));
  exit();
}

veritrans-php-v1's People

Contributors

aviandri avatar dnlwitono avatar fauzanahsan avatar mul14 avatar shaddiqa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.