<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
first-iraqi-bank / fib-laravel-payment-sdk example snippets
'providers' => [
// Other Service Providers...
FirstIraqiBank\FIBPaymentSDK\FIBPaymentServiceProvider::class,
],
use FirstIraqiBank\FIBPaymentSDK\Services\FIBPaymentIntegrationService;
protected $paymentService;
// Inject the FIBPaymentIntegrationService in your controller's construct.
public function __construct(FIBPaymentIntegrationService $paymentService)
{
$this->paymentService = $paymentService;
}
try {
// Call the createPayment method of the FIBPaymentIntegrationService
$response = $this->paymentService->createPayment(1000, 'http://localhost/callback', 'Your payment description');
$paymentData = json_decode($response->getBody(), true);
// Return a response with the payment details and structure it as per your need.
if($response->successful()) {
return response()->json([
'message' => 'Payment created successfully!',
'payment' => $paymentData,
]);
}
} catch (Exception $e) {
// Handle any errors that might occur.
return response()->json([
'message' => 'Error creating payment: ' . $e->getMessage()
], 500);
}
use FirstIraqiBank\FIBPaymentSDK\Services\FIBPaymentIntegrationService;
protected $paymentService;
// Inject the FIBPaymentIntegrationService in your controller's construct.
public function __construct(FIBPaymentIntegrationService $paymentService)
{
$this->paymentService = $paymentService;
}
try {
$paymentId = 'your_payment_id'; // Retrieve from your storage
// Call the checkPaymentStatus method of the FIBPaymentIntegrationService
$response = $this->paymentService->checkPaymentStatus($paymentId);
$paymentData = json_decode($response->getBody(), true);
//return the status and structure it as per your need.
if($response->successful()) {
return response()->json([
'status' => $paymentData['status'],
]);
} else{
return response()->json([
'data' => $paymentData,
]);
}
} catch (Exception $e) {
// Handle any errors that might occur
return response()->json([
'message' => 'Error creating payment: ' . $e->getMessage()
], 500);
}
use FirstIraqiBank\FIBPaymentSDK\Services\FIBPaymentIntegrationService;
protected $paymentService;
// Inject the FIBPaymentIntegrationService in your controller's construct.
public function __construct(FIBPaymentIntegrationService $paymentService)
{
$this->paymentService = $paymentService;
}
try {
$paymentId = 'your_payment_id'; // Retrieve from your storage
$response = $this->paymentService->refund($paymentId);
echo "Refund Payment Status: " . $response;
} catch (Exception $e) {
echo "Error Refunding payment: " . $e->getMessage();
}
use FirstIraqiBank\FIBPaymentSDK\Services\FIBPaymentIntegrationService;
protected $paymentService;
// Inject the FIBPaymentIntegrationService in your controller's construct.
public function __construct(FIBPaymentIntegrationService $paymentService)
{
$this->paymentService = $paymentService;
}
try {
$paymentId = 'your_payment_id'; // Retrieve from your storage
// Call the cancelPayment method of the FIBPaymentIntegrationService
$response = $this->paymentService->cancelPayment($paymentId);
//return the response and structure it as per your need.
if (in_array($response->getStatusCode(), [200, 201, 202, 204])) {
return response()->json([
'message' => "payment canceled Successfully",
]);
} else {
return response()->json([
'message' => "payment cancelation faild ",
'data' => $response->json()
]);
}
} catch (Exception $e) {
// Handle any errors that might occur
return response()->json([
'message' => 'Error creating payment: ' . $e->getMessage()
], 500);
}