1. Go to this page and download the library: Download mazimez/laravel-gigapay 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/ */
mazimez / laravel-gigapay example snippets
use Mazimez\Gigapay\Events\EmployeeClaimed;
use Mazimez\Gigapay\Events\EmployeeCreated;
use Mazimez\Gigapay\Events\EmployeeNotified;
use Mazimez\Gigapay\Events\EmployeeVerified;
use Mazimez\Gigapay\Events\InvoiceCreated;
use Mazimez\Gigapay\Events\InvoicePaid;
use Mazimez\Gigapay\Events\PayoutAccepted;
use Mazimez\Gigapay\Events\PayoutCreated;
use Mazimez\Gigapay\Events\PayoutNotified;
return [
/*
|--------------------------------------------------------------------------
| Gigapay Server URL
|--------------------------------------------------------------------------
|
| Gigapay generally has 2 servers, 1 for demo and 1 for production
| both server has different url, by default it will use the demo server URL
| but you can change it from your project's .env file.
| also currently Gigapay's APIs are at version 2, so it will use version 2
|
*/
'server_url' => env('GIGAPAY_SERVER_URL', 'https://api.demo.gigapay.se/v2'),
/*
|--------------------------------------------------------------------------
| Gigapay Token
|--------------------------------------------------------------------------
|
| Gigapay uses this token to identify and authenticate requests,
| you can get this Token from your Gigapay account
| Note that Tokens are different for demo server and production server
| define it in your .env.
|
*/
'token' => env('GIGAPAY_TOKEN'),
/*
|--------------------------------------------------------------------------
| Gigapay integration id
|--------------------------------------------------------------------------
|
| Integrations are like Transactions, it's a parent object of all other objects in the Gigapay API
| whenever you do any action in Gigapay, it will be in integration and it has a integration id
| Gigapay's API need integration id, you can create integration with Gigapay APIs from https://developer.gigapay.se/#create-an-integration
|
*/
'integration_id' => env('GIGAPAY_INTEGRATION_ID'),
/*
|--------------------------------------------------------------------------
| Gigapay lang
|--------------------------------------------------------------------------
|
| Language for the API responses. default will be english(en)
|
*/
'lang' => env('GIGAPAY_LANG', 'en'),
/*
|--------------------------------------------------------------------------
| Gigapay events mapping
|--------------------------------------------------------------------------
|
| mapping of Gigapay's different webhook events to route that will receive the webhook event
|
*/
'events_mapping' => [
'Employee.created' => 'employee-created',
'Employee.notified' => 'employee-notified',
'Employee.claimed' => 'employee-claimed',
'Employee.verified' => 'employee-verified',
'Payout.created' => 'payout-created',
'Payout.notified' => 'payout-notified',
'Payout.accepted' => 'payout-accepted',
'Invoice.created' => 'invoice-created',
'Invoice.paid' => 'invoice-paid',
],
/*
|--------------------------------------------------------------------------
| Gigapay Events
|--------------------------------------------------------------------------
|
| List of Gigapay events that you can listen to by Listeners.
|
*/
'events_list' => [
EmployeeClaimed::class,
EmployeeCreated::class,
EmployeeNotified::class,
EmployeeVerified::class,
InvoiceCreated::class,
InvoicePaid::class,
PayoutAccepted::class,
PayoutCreated::class,
PayoutNotified::class,
]
];
use Mazimez\Gigapay\Employee;
//#1 creating Employee by passing all data in arguments
$employee = Employee::create(
'jhone doe', //employee's name ( 'SWE', //employee's country
json_encode([
"data" => "data from your system" //any metadata that you want to add from you system(json encoded)
]),
'1-2-3' //employee's ID(has to be unique)
);
return $employee->getJson();
//#2 creating Employee by passing all data in an array
$employee = Employee::createByArray([
"id"=>"1-2-3", //employee's ID(has to be unique)
"name"=>"jhone doe", //employee's name (
use Mazimez\Gigapay\Employee;
//#1: updating values using separate methods
$employee = Employee::findById('123'); //finding employee by id
$employee = $employee->updateCountry('SWE'); //updating country
$employee = $employee->updateName("test employee"); //updating name
$employee = $employee->updateEmail("[email protected]"); //updating email
$employee = $employee->updateMetaDate(json_encode([
"data" => "some more data from you system", //updating metadata
]));
$employee = $employee->updateId('12354'); //updating id
return $employee->getJson();
//#2 updating values using save() methods
$employee = Employee::findById('dvsdvsdv'); //finding employee by id
$employee->country = "SWE"; //updating country
$employee->name = "test employee"; //updating name
$employee->email = "[email protected]"; //updating email
$employee->metadata = json_encode([
"data" => "some more data from you system", //updating metadata
]);
$employee->save(); //saving the employee object
return $employee->getJson();
use Mazimez\Gigapay\Employee;
$employees = Employee::list(); //getting list of employee
$employees = $employees->paginate(1, 5); //add pagination
return $employees->getJson();
use Mazimez\Gigapay\Employee;
$employee = Employee::findById('1'); //getting employee by it's id
return $employee->getJson();
use Mazimez\Gigapay\Employee;
$employee = Employee::findById('1'); //getting employee by it's id
$employee = $employee->replace([ //replacing the employee with new data
"id" => "1-2-3-4-5-6",
"name" => "jhone doe",
"email" => "[email protected]",
"metadata" => json_encode([
"data" => "data from your system"
]),
"country" => "SWE",
]);
return $employee->getJson(); //return the new employee instance
use Mazimez\Gigapay\Employee;
$employee = Employee::findById('1'); //getting employee by it's id
$employee->destroy(); //deletes the employee
return $employees->getJson(); //return the empty Employee instance
use Mazimez\Gigapay\Employee;
$employee = Employee::findById('1'); //getting employee by it's id
$employee->resend(); //resend invite to the employee
use Mazimez\Gigapay\Employee;
$employee = Employee::findById('1'); //getting employee by it's id
$payouts = $employee->getAllPayouts(); //gettin payouts for that perticular employee
return $payouts->getJson(); //returning the payouts in json
use Mazimez\Gigapay\Payout;
//#1 creating payout with arguments
$payout = Payout::create(
'9aa16b42-d0f3-420f-ba57-580c3c86c419', //employee id
'Instagram samarbete 2021-11-13.', //description for payout
120, //amount of payout
null, //cost of payout
null, //invoice amount of payout
'SEK', //currency of payout
json_encode([
"data" => "data from your system" //metadata of payout
]),
null, //The time at which the gig will start. Displayed as ISO 8601 string.
null, //The time at which the gig will end. Displayed as ISO 8601 string.
3 //Unique identifier for the object.
);
return $payout->getJson();
//#2 creating payout by array
$payout = Payout::createByArray([
"employee" => "1-2-3", //employee id
"invoiced_amount" => "120", //invoice amount of payout
"description" => "test description", //description for payout
"metadata" => json_encode([
"data" => "data from your system" //metadata of payout
]),
"currency"=>"SEK", //currency of payout
"id"=>"payout-1-2-3" //Unique identifier for the object.
]);
return $payout->getJson();
use Mazimez\Gigapay\Payout;
$payout = Payout::createInline(
[
"name" => "jhone dao", //name ( "cellphone_number" => "+46760024938"//phone number(optional)
], //inline employee data
'Instagram samarbete 2021-11-13.', //description for payout
null, //amount of payout
null, //cost of payout
120, //invoice amount of payout
'SEK', //currency of payout
json_encode([
"data" => "data from your system" //metadata of payout
]),
null, //The time at which the gig will start. Displayed as ISO 8601 string.
null, //The time at which the gig will end. Displayed as ISO 8601 string.
3 //Unique identifier for the object.
);
return $payout->getJson();
use Mazimez\Gigapay\Payout;
//creating 3 payouts to 3 different employees (with different specification)
$data = collect();
//any logic for calculating the payout value
$data->push([
"employee" => "employee-id-1",
"description" => "test description",
"invoiced_amount" => "210",
]);
//any logic for calculating the payout value
$data->push([
"employee" => "employee-id-2",
"description" => "test description",
"cost" => "210",
"country" => "SWE",
"metadata" => [
"data" => "data about your system"
],
]);
//any logic for calculating the payout value
$data->push([
"id" => "test-id",
"employee" => "employee-id-3",
"description" => "test description",
"amount" => "210",
"country" => "SWE",
"currency" => "SEK"
]);
//creating multiple payouts by giving the array
$payouts = Payout::createMultiple($data->toArray());
return $payouts; //returns an array of Payout objects
use Mazimez\Gigapay\Payout;
$payouts = Payout::list(); //getting list of employee
$payouts = $payouts->paginate(1, 5); //add pagination
return $payouts->getJson();
use Mazimez\Gigapay\Payout;
$payout = Payout::findById('1'); //getting payout by it's id
return $payout->getJson();
use Mazimez\Gigapay\Payout;
$payout = Payout::findById('1'); //getting payout by it's id
$payout->destroy(); //deletes the payout
return $payout->getJson(); //return the empty payout instance
use Mazimez\Gigapay\Payout;
$payout = Payout::findById('89f9cfbe-f1ec-4d17-a895-21cdb584eb4d'); //getting payout by it's id
$payout->resend(); //resend mail to the employee
use Mazimez\Gigapay\Payout;
$payout = Payout::findById('89f9cfbe-f1ec-4d17-a895-21cdb584eb4d'); //getting payout by it's id
$payout->expandInvoice()->expandEmployee();//expanding invoice and employee field
return $payout->getJson(); //returning the payouts in json(with expanded values)
use Mazimez\Gigapay\Invoice;
$invoices = Invoice::list(); //getting list of invoices
$invoices = $invoices->paginate(1, 5); //add pagination
return $invoices->getJson();
use Mazimez\Gigapay\Invoice;
$invoice = Invoice::findById('f3ee8cb8-fc95-4ea2-9b2e-18875b0d759a');//getting invoice by it's ID
return $invoice->getJson();
use Mazimez\Gigapay\Invoice;
//#1: updating values using separate methods
$invoice = Invoice::findById('4bb6bd41-643e-43fe-af09-206c755088c9');
$invoice = $invoice->updateId("123"); //updating id
$invoice =$invoice->updateMetaDate(json_encode([
"data" => "data from your system" //updating metadata
]));
//#2 updating values using save() methods
$invoice->metadata = json_encode([
"data" => "data from your system" //updating metadata
]);
$invoice->save();
use Mazimez\Gigapay\Invoice;
$invoice = Invoice::findById('f3ee8cb8-fc95-4ea2-9b2e-18875b0d759a');//getting invoice by it's ID
$invoice->destroy(); //deletes the invoice
return $invoice->getJson(); //return the empty invoice instance
use Mazimez\Gigapay\Pricing;
$pricing = Pricing::list(); //getting list of pricing
$pricing = $pricing->paginate(1, 5); //add pagination
return $pricing->getJson();
use Mazimez\Gigapay\Pricing;
$pricing = Pricing::findById('89f9cfbe-f1ec-4d17-a895-21cdb584eb4d')//getting pricing info by payout's ID
return $pricing->getJson();
use Mazimez\Gigapay\Pricing;
$pricing = Pricing::calculatePricing(
'0d42728d-b565-402d-80aa-a20bec94a9a2', //id of employee that you want to pay
'SEK', //currency of payout
null, //cost (only 1 out cost, amount and invoiced_amount is allowed)
'120', //amount (only 1 out cost, amount and invoiced_amount is allowed)
null, //invoiced_amount (only 1 out cost, amount and invoiced_amount is allowed)
'test', //description
false, //full_salary_specification
json_encode([
"data" => "data from your system" //metadata of payout
]),
null, //start_at
null, //end_at
null, //id
);
return $pricing->getJson();
use Mazimez\Gigapay\Pricing;
//calculating pricing info for 3 different payouts to 3 different employees (with different specifications)
$pricings = Pricing::calculateBulk([
[
"employee" => "employee-id-1",
"invoiced_amount" => "210",
],
[
"employee" => "employee-id-2",
"description" => "test description",
"cost" => "210",
"country" => "SWE",
],
[
"id" => "test-id",
"employee" => "employee-id-3",
"description" => "test description",
"amount" => "210",
"country" => "SWE",
"currency" => "SEK"
],
]);
return $pricings; //returns an array of pricing objects
/**
* Determine if events and listeners should be automatically discovered.
*
* @return bool
*/
public function shouldDiscoverEvents()
{
return true;
}
namespace App\Listeners;
use Mazimez\Gigapay\Events\EmployeeCreated;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
class EmployeeCreatedListener
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param EmployeeCreated $event
* @return void
*/
public function handle(EmployeeCreated $event)
{
//stuff you can do with this event resource to update you system
$employee = $event->getResource();
//logging data just as an example
$logger = new Logger('gigapay-webhooks-logs');
$logger->pushHandler(new StreamHandler(storage_path('logs/gigapay/gigapay-webhooks-logs.log')));
$logger->info('employee created with id of ' . $employee->id);
}
}
use Mazimez\Gigapay\Webhook;
$webhooks = Webhook::list(); //getting list of webhooks
$webhooks = $webhooks->paginate(1, 5); //add pagination
return $webhooks->getJson();
use Mazimez\Gigapay\Webhook;
//creating webhook with create method
$webhook = Webhook::create(
"https://youwebsite.url/webhooks", //the url on which the webhook will send data
"Employee.created", //name of event
null, //secret_key
json_encode(["date" => "data from your system"]),//json encoded data
null, //unique id
);
return $webhook->getJson();
//creating webhook with createByArray method(only
use Mazimez\Gigapay\Webhook;
$webhook = Webhook::findById('1'); //getting webhook by it's id
return $webhook->getJson();
use Mazimez\Gigapay\Webhook;
//#1: updating values using separate methods
$webhook = Webhook::findById('webhook-id'); //finding webhook by id
$webhook = $webhook->updateId('new-webhook-id'); //updating id
$webhook = $webhook->updateUrl("https://youwebsite.new.url/webhooks"); //updating url
$webhook = $webhook->updateEvent("Payout.created"); //updating event
$webhook = $webhook->updateSecretKey("new-secret.key"); //updating secret-key
$webhook = $webhook->updateMetaDate(json_encode([
"data" => "some more data from you system", //updating metadata
]));
return $webhook->getJson();
//#2 updating values using save() methods
$webhook = Webhook::findById('webhook-id'); //finding webhook by id
$webhook->url = "https://youwebsite.new.url/webhooks"; //updating url
$webhook->event = "Payout.created"; //updating event
$webhook->secret_key = "new-secret.key"; //secret-key
$webhook->metadata = json_encode([
"data" => "some more data from you system", //updating metadata
]);
$webhook->save(); //saving the webhook object
return $webhook->getJson();
use Mazimez\Gigapay\Webhook;
$webhook = Webhook::findById('1'); //getting webhook by it's id
$webhook->replace([//replacing webhook with new data
'url' => "https://jobmatchr.se/webhooks/"
]);
return $webhook->getJson();//returning new webhook instance
use Mazimez\Gigapay\Webhook;
$webhook = Webhook::findById('webhook-id'); //getting webhook by it's id
$webhook->destroy(); //deletes the webhook
return $webhooks->getJson(); //return the empty webhook instance
use Mazimez\Gigapay\Employee;
$employees = Employee::list();
$employees->paginate($page, $page_size); //paginate methode with parameters
return $employees->getJson();
use Mazimez\Gigapay\Payout;
$payouts = Payout::list();
//exapanding employee and invoice resource
$payouts->expand('employee')->expand('invoice');
return $payouts->getJson();
use Mazimez\Gigapay\Employee;
$employees = Employee::list();
//adding filter to get the employees who are created before 10 days
$employees->addFilter('created_at_before', Carbon::now()->subDays(10)->toISOString());
//adding filter to get the onty verfied employees.
$invoice->addFilter('verified_at_null', 'false');
return $invoice->getJson();
use Mazimez\Gigapay\Employee;
$employees = Employee::list();
return $invoice->getJson(); //returning json response
use Mazimez\Gigapay\Exceptions\GigapayException;
use Mazimez\Gigapay\Invoice;
try {
return Invoice::findById("non-exiting-id")->getJson(); //code that will surely gives error.
} catch (GigapayException $th) { //catching the error with GigapayException
return [
'message' => $th->getErrorMessage(), //the error message
'json' => $th->getJson() //the json
];
} catch (Exception $th) {
return $th->getMessage(); //catching exception other then GigapayException
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.