Viewing file: SSLCommerz.php (6.02 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace Modules\PaymentGateway\WHNPurchaseGateway;
use App\Models\BillingRequest;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Modules\PaymentGateway\Services\PaymentCredentials;
class SSLCommerz implements PaymentInterface
{
public $numberReq;
public $redirect_url;
public $error_message;
public $return_view;
public $will_redirect = false;
public function __construct()
{
}
public function pay()
{
// TODO: Implement pay() method.
}
public function getCredentials()
{
$credentials= json_decode(get_settings('payment_gateway'));
if (!isset($credentials->sslcommerz_status) || !$credentials->sslcommerz_store_id || $credentials->sslcommerz_status != 'active' ||
!isset($credentials->sslcommerz_store_password) || !isset($credentials->sslcommerz_url)) {
throw new \Exception('Credentials not found. Please contact with the administrator');
}
return $credentials;
}
public function request($request)
{
$this->request = $request;
return $this;
}
public function number($number)
{
$this->number = $number;
return $this;
}
public function number_request($numberReq)
{
$this->numberReq = $numberReq;
return $this;
}
public function will_redirect()
{
// TODO: Implement will_redirect() method.
return $this->will_redirect;
}
public function redirect_url()
{
// TODO: Implement redirect_url() method.
return $this->redirect_url;
}
public function return_view()
{
// TODO: Implement redirect_url() method.
return $this->return_view;
}
public function error_message()
{
// TODO: Implement error_message() method.
return $this->error_message;
}
public function process()
{
$customer= auth('customer')->user();
try {
if (!$this->request->payment_number) {
throw new \Exception('Phone number not found, provide phone number and try again');
}
$credentials = $this->getCredentials();
$post_data = array();
$post_data['store_id'] = $credentials->sslcommerz_store_id;
$post_data['store_passwd'] = $credentials->sslcommerz_store_password;
$post_data['total_amount'] = $this->number->sell_price;
$post_data['currency'] = "BDT";
$post_data['tran_id'] = "SSLCZ_TEST_" . uniqid();
$post_data['success_url'] = route('paymentgateway::whatsapp.number.purchase.ssl.success');
$post_data['fail_url'] = route('paymentgateway::v.payment.process.cancel');
$post_data['cancel_url'] = route('paymentgateway::whatsapp.payment.process.cancel');
# EMI INFO
$post_data['emi_option'] = "1";
$post_data['emi_max_inst_option'] = "9";
$post_data['emi_selected_inst'] = "9";
# CUSTOMER INFORMATION
$post_data['cus_name'] = $customer->fullname;
$post_data['cus_email'] = $customer->email;
$post_data['cus_add1'] = "Demo-".$customer->id;
$post_data['cus_add2'] = "Dhaka";
$post_data['cus_city'] = "Dhaka";
$post_data['cus_state'] = "Dhaka";
$post_data['cus_postcode'] = "1000";
$post_data['cus_country'] = "Bangladesh";
$post_data['cus_phone'] = $this->request->payment_number;
$post_data['cus_fax'] = $this->request->payment_number;
# SHIPMENT INFORMATION
$post_data['ship_name'] = "Store Test";
$post_data['ship_add1 '] = "A";
$post_data['ship_add2'] = "B";
$post_data['ship_city'] = "C";
$post_data['ship_state'] = "D";
$post_data['ship_postcode'] = "0000";
$post_data['ship_country'] = "E";
$post_data['shipping_method'] = "NO";
# OPTIONAL PARAMETERS
$post_data['value_a'] = $this->number->id;
$post_data['value_b'] = $this->numberReq->id;
$post_data['value_c'] = $customer->id;
$post_data['product_name'] = $this->number->number;
$post_data['product_category'] = $this->number->number;
$post_data['product_profile'] = "general";
$post_data['product_amount'] = $this->number->sell_price;
$post_data['vat'] = "0";
$post_data['discount_amount'] = "0";
$post_data['convenience_fee'] = "0";
// $direct_api_url = "https://sandbox.sslcommerz.com/gwprocess/v4/api.php";
$direct_api_url = $credentials->sslcommerz_url;
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $direct_api_url);
curl_setopt($handle, CURLOPT_TIMEOUT, 30);
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($handle, CURLOPT_POST, 1);
curl_setopt($handle, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, FALSE); # KEEP IT FALSE IF YOU RUN FROM LOCAL PC
$content = curl_exec($handle);
$code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
if($code == 200 && !( curl_errno($handle))) {
curl_close( $handle);
$sslcommerzResponse = $content;
} else {
curl_close( $handle);
echo "FAILED TO CONNECT WITH SSLCOMMERZ API";
}
# PARSE THE JSON RESPONSE
$sslcz = json_decode($sslcommerzResponse, true );
$this->redirect_url = $sslcz['GatewayPageURL'];
$this->will_redirect = true;
$this->return_view = null;
}catch(\Exception $ex){
Log::error($ex);
$this->error_message= $ex->getMessage();
}
}
}
|