PHP code example of maq89 / paytabs-symfony

1. Go to this page and download the library: Download maq89/paytabs-symfony library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

maq89 / paytabs-symfony example snippets


composer 

$bundles = array(
	// ...
	new Damas\PaytabsBundle\DamasPaytabsBundle(),
	// ...
);

use Damas\PaytabsBundle\Util\Paytabs;

$pt = Paytabs::getInstance("MERCHANT_EMAIL", "SECRET_KEY");
$result = $pt->create_pay_page(array(
	"merchant_email" => "MERCHANT_EMAIL",
	'secret_key' => "SECRET_KEY",
	'title' => "John Doe",
	'cc_first_name' => "John",
	'cc_last_name' => "Doe",
	'email' => "[email protected]",
	'cc_phone_number' => "973",
	'phone_number' => "33333333",
	'billing_address' => "Juffair, Manama, Bahrain",
	'city' => "Manama",
	'state' => "Capital",
	'postal_code' => "97300",
	'country' => "BHR",
	'address_shipping' => "Juffair, Manama, Bahrain",
	'city_shipping' => "Manama",
	'state_shipping' => "Capital",
	'postal_code_shipping' => "97300",
	'country_shipping' => "BHR",
	"products_per_title"=> "Mobile Phone",
	'currency' => "BHD",
	"unit_price"=> "10",
	'quantity' => "1",
	'other_charges' => "0",
	'amount' => "10.00",
	'discount'=>"0",
	"msg_lang" => "english",
	"reference_no" => "1231231",
	"site_url" => "https://your-site.com",
	'return_url' => "http://127.0.0.1:8000/paytabs-response",
	"cms_with_version" => "API USING PHP"
));


if($result->response_code == 4012){
	return $this->redirect($result->payment_url);
}
else{
	throw new \Exception($result->result);	
}

$pt = Paytabs::getInstance("MERCHANT_EMAIL", "SECRET_KEY");
$result = $pt->verify_payment($request->request->get('payment_reference'));
if($result->response_code == 100){
	// Payment Success
}
else{
	throw new \Exception($result->result);	
}