Skip to content

Moyasar Gateway

php anonymous edited this page Oct 14, 2021 · 3 revisions

Moyasar Gateway

It is known that these gate are easy to use and do not require many settings

So we will learn how to use the package with this payment gateway

usage

after login your account from this url https://dashboard.moyasar.com/session/login

must configure your config/gateways.php in section

'moyassar' => [
			"mode" => "sandbox", // sandbox , live
			"test_secret_key" => "",
			"test_publishable_key" => "",
			"live_secret_key" => "",
			"live_publishable_key" => "",
		],

after set your mode and keys

should be this package builded based on this moyasar api https://moyasar.com/docs/api/?php#introduction

There will not be any section outside this explanation in the link above

now with every link and every single value

You will be able to use the code quite easily, you just have to read the content of the link and you will know here what you have to do

CREDITCARD

// create payment https://moyasar.com/docs/api/?php#create-a-payment
$gateway = gateway('moyassar')
	->method('CREDITCARD') // available methods 'CREDITCARD', 'APPLEPAY', 'STCPAY', 'SADAD', 'MADA'
	//->redirect() // redirect method - to force redirect if request initiated
	->query([
		'currency' => 'SAR',
		'amount' => '50000',
		'source[3ds]' => true,
		'source[name]' => 'Mahmoud Mohamed',
		'source[number]' => '4111111111111111',
		'source[cvc]' => '123',
		'source[month]' => '11',
		'source[year]' => '21',
		'description' => 'test Desc',
		'callback_url' => url('gateway'),
	])
	->purchase();
// ->redirect() this method  When you turn it on, you will be automatically transferred to the payment link

APPLEPAY

gateway('moyassar')
	->method('APPLEPAY')
	//->redirect() // redirect method - to force redirect if request initiated
	->query([
		'source[token]' => 'token_here',
		'amount' => '50000',
		'source[3ds]' => true,
		'description' => 'test Desc',
		'callback_url' => url('gateway'),
	])
	->purchase();

STCPAY

 gateway('moyassar')
	->method('STCPAY')
	//->redirect() // redirect method - to force redirect if request initiated
	->query([
		'source[mobile]' => 'asdddsas',
		'source[branch]' => 'asdddsas',
		'source[cashier]' => 'asdddsas',
		'amount' => '50000',
		'source[3ds]' => true,
		'description' => 'test Desc',
		'callback_url' => url('gateway'),
	])
	->purchase();

Fetch a payment

// Fetch a payment https://moyasar.com/docs/api/?php#fetch-a-payment
 gateway('moyassar')->fetch('your_payment_id');

capture a payment

// capture a payment https://moyasar.com/docs/api/?php#capture-a-payment
gateway('moyassar')->query([
	'amount' => '200', // optional
])->capture('your_payment_id');
// or 
gateway('moyassar')->capture('your_payment_id');

cancel a paid

// cancel a paid https://moyasar.com/docs/api/?php#void-a-payment
 gateway('moyassar')->unPaid('your_payment_id');

refund a payment

// refund a payment https://moyasar.com/docs/api/?php#refund-a-payment
gateway('moyassar')
	->query([
		'amount' => '200', // optional
	])->refund('e5c24938-6d3c-4045-abf9-bddf3e58f520');
// or 
gateway('moyassar')->refund('your_payment_id');

update description

// update description payment https://moyasar.com/docs/api/?php#update-a-payment
$gateway = gateway('moyassar')->query([
	'description' => 'new description ',
])->update('your_payment_id');

List payments

 gateway('moyassar')
	->query([
		//'id' => '',
		'source' => 'all', // (all/stcpay/creditcard/mada/applepay)
		'page' => '3',
		'status' => 'all', // all,initiated,paid,authorized,captured,failed,refunded,voided,abandoned
		//'created[gt]' => '13/12/2017',
		//'created[lt]' => '21/04/2018',
		//'metadata[email]' => '[email protected]', //metadata[key]
	])->get();