1. Go to this page and download the library: Download iammiloslukic/nestpay library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?phprequire_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
iammiloslukic / nestpay example snippets
useCubes\Nestpay\MerchantService;
//...
$nestpayMerchantService = new MerchantService([
'clientId' => '********',
'storeKey' => '********',
'storeType' => '3D_PAY_HOSTING',
'okUrl' => 'http://localhost:8082/examples/success.php', //this could be configured later'failUrl' => 'http://localhost:8082/examples/failed.php', //this could be configured later'3DGateUrl' => 'https://testsecurepay.eway2pay.com/fim/est3Dgate',
//API'apiName' => '********',
'apiPassword' => '********',
'apiEndpointUrl' => 'https://testsecurepay.eway2pay.com/fim/api'
]);
$nestpayMerchantService->setPDO($pdo); //$pdo is instanceof \PDO
$nestpayMerchantService->setPDO($pdo, 'your_table'); //'your_table' is name of the table for payments
$merchantService->onFailedPayment(function($payment){
//$payment is instance of \ReadyCMSIO\Nestpay\Payment//send an email for failed payment attempt// $email = $payment->getProperty(\ReadyCMSIO\Nestpay\Payment::PROP_EMAIL);// $customerName = $payment->getProperty(\ReadyCMSIO\Nestpay\Payment::PROP_BILLTONAME);
})->onSuccessfulPayment(function($payment){
//$payment is instance of \ReadyCMSIO\Nestpay\Payment//send an email for successful payment// $email = $payment->getProperty(\ReadyCMSIO\Nestpay\Payment::PROP_EMAIL);// $customerName = $payment->getProperty(\ReadyCMSIO\Nestpay\Payment::PROP_BILLTONAME);//do stuff related to the siccessfull payment
});
$payment = $nestpayMerchantService->paymentProcess3DGateResponse($_POST);
//DO NOT SEND EMAIL HERE OR DO SOME ACTION ON SUCCESSFUL PAYMENT, JUST SHOW RESULT!//USE $nestpayMerchantService->onSuccessfulPayment INSTEAD!!!//display results of the payment:
//second parameter (true) indicates that this processing is on fail url
$payment = $nestpayMerchantService->paymentProcess3DGateResponse($_POST, true);
//display resultsu of the payment:
//$oid is the OID of some unprocessed payment (WHERE `processed` != 1)
$payment = $nestpayMerchantService->paymentProcessOverNestpayApi($oid);
//DO NOT SEND EMAIL HERE OR DO SOME ACTION ON SUCCESSFUL PAYMENT!//USE $nestpayMerchantService->onSuccessfulPayment INSTEAD!!!
//$oid is the OID of the payment
$result = $nestpayMerchantService->postAuthorizationOverNestpayApi($oid);
//$oid is the OID of the payment//$amount should not be greated than the orginal amount reserved in PreAuth
$result = $nestpayMerchantService->postAuthorizationOverNestpayApi($oid, $amount);
//$oid is the OID of the payment
$result = $nestpayMerchantService->voidOverNestpayApi($oid);
//$payment is instance of \ReadyCMSIO\Nestpay\Payment
$payment = $nestpayMerchantService->getWorkingPayment();
//get some of the payment properties
$email = $payment->getProperty(\ReadyCMSIO\Nestpay\Payment::PROPERTY_EMAIL);
//for some important properties there are getters
$email = $payment->getEmail();
use \ReadyCMSIO\Nestpay\PaymentDao;
use \ReadyCMSIO\Nestpay\Payment;
classMyPaymentDaoimplementsPaymentDao{
/**
* Fetch payment by $oid
*
* @return \ReadyCMSIO\Nestpay\Payment
* @param scalar $oid
*/publicfunctiongetPayment($oid){
//return payment by oid
}
/**
* Saves the payment
*
* @param \ReadyCMSIO\Nestpay\Payment $payment
* @return \ReadyCMSIO\Nestpay\Payment
*/publicfunctionsavePayment(Payment $payment){
//save existing payment
}
/**
* Creates new payment
*
* @param array $properties
* @return \ReadyCMSIO\Nestpay\Payment
*/publicfunctioncreatePayment(array $properties){
//create new payment
}
}
//THIS IS config/app.phpreturn [
//got to providers key// ...'providers' => [
//...
\ReadyCMSIO\Nestpay\Laravel\NestpayServiceProvider::class
],
'aliases' => [
//...// optinally add alias for facade'Nestpay' => \ReadyCMSIO\Nestpay\Laravel\Facade::class,
],
];
namespaceApp\Http\Controllers;
use \ReadyCMSIO\Nestpay\MerchantService;
classTestControllerextendsController{
publicfunctionindex(MerchantService $merchantService){
}
}
//Using facade
\Nestpay::paymentProcess3DGateResponse($request->all());
//using service container with "nestpay" key
app('nestpay')->paymentProcessOverNestpayApi($nestpayPayment->oid);
//file: config/nestpay.phpreturn [
'merchant' => [/* the mercant configuration*/],
//change this if you want to use some other class for payment model//Object of paymentModel class is going to be returned when calling MerchantService::getWorkingPayment'paymentModel' => \App\Models\NestpayPayment::class
//...
];
//file: database/migrations/2020_03_27_144802_create_nestpay_payments_table.phppublicfunctionup(){
Schema::create($this->tableName, function(Blueprint $table){
$table->bigIncrements('id');
$table->tinyInteger('processed')->default(0)->comment('1-processed; 0-not_processed');
$table->char('oid', 64)->comment('Unique identifier of the order');
// add your application specific fields like user_id or order_id etc..//DO NOT REMOVE ANY OF EXISTING COLUMNS!!!
//file: app\Migrations\NestpayPaymentnamespaceApp\Models;
useCubes\Nestpay\Laravel\PaymentModelasModel;
classNestpayPaymentextendsModel{
protected $table = 'nestpay_payments';
protected $fillable = [
//DO NOT REMOVE ANY FILLABLES JUST ADD NEW ONE FOOUR APPLICATION'processed',
'oid',
'trantype',
//...
classNestpayControllerextendsController{
...
//You should definitively start from this point//customize how to read amount, currenct customer email and other stuff from your applicationprotectedfunctiongetPaymentData(){
//...
}
}
//file: app/Http/Middleware/VerifyCsrfToken.phpclassVerifyCsrfTokenextendsMiddleware{
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/protected $except = [
'/nestpay/success', //change this if you have customized routes'/nestpay/fail', //change this if you have customized routes
];
}