Testing callback on server
This commit is contained in:
264
Modules/Linksehat/Http/Controllers/Api/DuitkuController.php
Normal file
264
Modules/Linksehat/Http/Controllers/Api/DuitkuController.php
Normal file
@@ -0,0 +1,264 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Linksehat\Http\Controllers\Api;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Organization;
|
||||
use App\Models\Speciality;
|
||||
use Illuminate\Contracts\Support\Renderable;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class DuitkuController extends Controller
|
||||
{
|
||||
public function configuration()
|
||||
{
|
||||
$duitkuConfig = new \Duitku\Config(env('API_KEY_DUITKU'), env('CODE_MERCHANT_DUITKU'));
|
||||
// false for production mode
|
||||
// true for sandbox mode
|
||||
$duitkuConfig->setSandboxMode(true);
|
||||
// set sanitizer (default : true)
|
||||
$duitkuConfig->setSanitizedMode(false);
|
||||
// set log parameter (default : true)
|
||||
$duitkuConfig->setDuitkuLogs(false);
|
||||
return $duitkuConfig;
|
||||
}
|
||||
|
||||
public function createInvoice(Request $request)
|
||||
{
|
||||
$data = [
|
||||
'paymentMethod' => $request->paymentMethod,
|
||||
'paymentAmount' => $request->paymentAmount,
|
||||
'email' => $request->email,
|
||||
'phoneNumber' => $request->phoneNumber,
|
||||
'productDetails' => $request->productDetails,
|
||||
'merchantOrderId' => $request->merchantOrderId,
|
||||
'additionalParam' => $request->additionalParam,
|
||||
'merchantUserInfo' => $request->merchantUserInfo,
|
||||
'customerVaName' => $request->customerVaName,
|
||||
// 'callbackUrl' => $request->callbackUrl,
|
||||
// 'returnUrl' => $request->returnUrl,
|
||||
// 'expiryPeriod' => $request->expiryPeriod,
|
||||
'firstName' => $request->firstName,
|
||||
'lastName' => $request->lastName,
|
||||
'alamat' => $request->alamat,
|
||||
'city' => $request->city,
|
||||
'postalCode' => $request->postalCode,
|
||||
// 'countryCode' => $request->countryCode
|
||||
];
|
||||
$validator = Validator::make($request->all(), [
|
||||
'paymentMethod' => 'nullable',
|
||||
'paymentAmount' => 'required',
|
||||
'email' => 'required|email',
|
||||
'phoneNumber' => 'nullable',
|
||||
'productDetails' => 'required',
|
||||
'merchantOrderId' => 'required',
|
||||
'additionalParam' => 'nullable',
|
||||
'merchantUserInfo' => 'nullable',
|
||||
'customerVaName' => 'required',
|
||||
// 'callbackUrl' => 'required',
|
||||
// 'returnUrl' => 'nullable',
|
||||
// 'expiryPeriod' => 'required',
|
||||
'firstName' => 'required',
|
||||
'lastName' => 'required',
|
||||
'alamat' => 'required',
|
||||
'city' => 'required',
|
||||
'postalCode' => 'required',
|
||||
// 'countryCode' => 'required'
|
||||
|
||||
], [
|
||||
'paymentAmount.required' => 'Jumlah pembayaran harus diisi',
|
||||
'email.required' => 'Email harus diisi',
|
||||
'email.email' => 'Format email salah',
|
||||
'productDetails.required' => 'Judul pembayaran harus diisi',
|
||||
'merchantOrderId.required' => 'Order ID harus diisi',
|
||||
'customerVaName.required' => 'Nama panggilan pelanggan harus diisi',
|
||||
'firstName.required' => 'Nama depan pelanggan harus diisi',
|
||||
'lastName.required' => 'Nama belakang pelanggan harus diisi',
|
||||
'alamat.required' => 'Alamat pelanggan harus diisi',
|
||||
'city.required' => 'Kota pelanggan harus diisi',
|
||||
'postalCode.required' => 'Kode pos pelanggan harus diisi',
|
||||
]);
|
||||
|
||||
if ($validator->fails())
|
||||
{
|
||||
return Helper::responseJson(
|
||||
data: $data,
|
||||
status: 'Bad Request',
|
||||
statusCode: 400,
|
||||
message: $validator->errors()
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
#CONTOH DARI DUITKU
|
||||
// $paymentMethod = ""; // PaymentMethod list => https://docs.duitku.com/pop/id/#payment-method
|
||||
// $paymentAmount = 10000; // Amount
|
||||
// $email = "customer@gmail.com"; // your customer email
|
||||
// $phoneNumber = "081234567890"; // your customer phone number (optional)
|
||||
// $productDetails = "Test Payment";
|
||||
// $merchantOrderId = "2"; // from merchant, unique
|
||||
// $additionalParam = ''; // optional
|
||||
// $merchantUserInfo = ''; // optional
|
||||
// $customerVaName = 'John Doe'; // display name on bank confirmation display
|
||||
// $callbackUrl = 'http://YOUR_SERVER/callback'; // url for callback
|
||||
// $returnUrl = 'http://YOUR_SERVER/return'; // url for redirect
|
||||
// $expiryPeriod = 60; // set the expired time in minutes
|
||||
|
||||
// // Customer Detail
|
||||
// $firstName = "John";
|
||||
// $lastName = "Doe";
|
||||
|
||||
// // Address
|
||||
// $alamat = "Jl. Kembangan Raya";
|
||||
// $city = "Jakarta";
|
||||
// $postalCode = "11530";
|
||||
// $countryCode = "ID";
|
||||
|
||||
$paymentMethod = $request->paymentMethod; // PaymentMethod list => https://docs.duitku.com/pop/id/#payment-method
|
||||
$paymentAmount = $request->paymentAmount; // Amount
|
||||
$email = $request->email; // your customer email
|
||||
$phoneNumber = $request->phoneNumber; // your customer phone number (optional)
|
||||
$productDetails = $request->productDetails;
|
||||
$merchantOrderId = $request->merchantOrderId; // from merchant, unique
|
||||
$additionalParam = $request->additionalParam; // optional
|
||||
$merchantUserInfo = $request->merchantUserInfo; // optional
|
||||
$customerVaName = $request->customerVaName; // display name on bank confirmation display
|
||||
$callbackUrl = env('APP_URL').'/api/linksehat/callback-duitku'; // url for callback
|
||||
$returnUrl = ''; // url for redirect
|
||||
$expiryPeriod = 60; // set the expired time in minutes
|
||||
|
||||
// Customer Detail
|
||||
$firstName = $request->firstName;
|
||||
$lastName = $request->lastName;
|
||||
|
||||
// Address
|
||||
$alamat = $request->alamat;
|
||||
$city = $request->city;
|
||||
$postalCode = $request->postalCode;
|
||||
$countryCode = "ID";
|
||||
|
||||
$address = array(
|
||||
'firstName' => $firstName,
|
||||
'lastName' => $lastName,
|
||||
'address' => $alamat,
|
||||
'city' => $city,
|
||||
'postalCode' => $postalCode,
|
||||
'phone' => $phoneNumber,
|
||||
'countryCode' => $countryCode
|
||||
);
|
||||
|
||||
$customerDetail = array(
|
||||
'firstName' => $firstName,
|
||||
'lastName' => $lastName,
|
||||
'email' => $email,
|
||||
'phoneNumber' => $phoneNumber,
|
||||
'billingAddress' => $address,
|
||||
'shippingAddress' => $address
|
||||
);
|
||||
|
||||
// Item Details
|
||||
$item1 = array(
|
||||
'name' => $productDetails,
|
||||
'price' => $paymentAmount,
|
||||
'quantity' => 1
|
||||
);
|
||||
|
||||
$itemDetails = array(
|
||||
$item1
|
||||
);
|
||||
|
||||
$params = array(
|
||||
'paymentAmount' => $paymentAmount,
|
||||
'merchantOrderId' => $merchantOrderId,
|
||||
'productDetails' => $productDetails,
|
||||
'additionalParam' => $additionalParam,
|
||||
'merchantUserInfo' => $merchantUserInfo,
|
||||
'customerVaName' => $customerVaName,
|
||||
'email' => $email,
|
||||
'phoneNumber' => $phoneNumber,
|
||||
'itemDetails' => $itemDetails,
|
||||
'customerDetail' => $customerDetail,
|
||||
'callbackUrl' => $callbackUrl,
|
||||
'returnUrl' => $returnUrl,
|
||||
'expiryPeriod' => $expiryPeriod
|
||||
);
|
||||
$duitkuConfig = $this->configuration();
|
||||
try {
|
||||
// createInvoice Request
|
||||
$responseDuitkuPop = \Duitku\Pop::createInvoice($params, $duitkuConfig);
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo $responseDuitkuPop;
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function paymentMethod(Request $request)
|
||||
{
|
||||
$duitkuConfig = $this->configuration();
|
||||
try {
|
||||
$paymentAmount = "10000"; //"YOUR_AMOUNT";
|
||||
$paymentMethodList = \Duitku\Pop::getPaymentMethod($paymentAmount, $duitkuConfig);
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo $paymentMethodList;
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public function checkStatus(Request $request)
|
||||
{
|
||||
$duitkuConfig = $this->configuration();
|
||||
try {
|
||||
$merchantOrderId = "2";
|
||||
$transactionList = \Duitku\Pop::transactionStatus($merchantOrderId, $duitkuConfig);
|
||||
|
||||
header('Content-Type: application/json');
|
||||
$transaction = json_decode($transactionList);
|
||||
|
||||
// var_dump($transactionList);
|
||||
|
||||
if ($transaction->statusCode == "00") {
|
||||
// Action Success
|
||||
} else if ($transaction->statusCode == "01") {
|
||||
// Action Pending
|
||||
} else {
|
||||
// Action Failed Or Expired
|
||||
}
|
||||
echo $transaction->statusCode;
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public function callback(Request $request)
|
||||
{
|
||||
$duitkuConfig = $this->configuration();
|
||||
try {
|
||||
$callback = \Duitku\Pop::callback($duitkuConfig);
|
||||
|
||||
header('Content-Type: application/json');
|
||||
$notif = json_decode($callback);
|
||||
|
||||
// var_dump($callback);
|
||||
|
||||
if ($notif->resultCode == "00") {
|
||||
// Action Success
|
||||
} else if ($notif->resultCode == "01") {
|
||||
// Action Failed
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
http_response_code(400);
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user