Merge remote-tracking branch 'origin/staging' into origin/production
This commit is contained in:
167
app/Helpers/DuitkuHelper.php
Normal file
167
app/Helpers/DuitkuHelper.php
Normal file
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
class DuitkuHelper
|
||||
{
|
||||
public static 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 static function paymentMethod()
|
||||
{
|
||||
$duitkuConfig = self::configuration();
|
||||
try {
|
||||
$paymentAmount = "10000"; //"YOUR_AMOUNT";
|
||||
$paymentMethodList = \Duitku\Pop::getPaymentMethod($paymentAmount, $duitkuConfig);
|
||||
|
||||
header('Content-Type: application/json');
|
||||
return $paymentMethodList;
|
||||
} catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public static function checkStatus($merchantOrderId)
|
||||
{
|
||||
$duitkuConfig = self::configuration();
|
||||
$data = [
|
||||
'merchantOrderId' => $merchantOrderId
|
||||
];
|
||||
try {
|
||||
$transactionList = \Duitku\Pop::transactionStatus($merchantOrderId, $duitkuConfig);
|
||||
|
||||
$transaction = json_decode($transactionList);
|
||||
|
||||
if ($transaction->statusCode == "00" || $transaction->statusCode == "01") {
|
||||
// Transaksi berhasil atau dalam proses
|
||||
return $transaction;
|
||||
} else {
|
||||
// Transaksi gagal atau kedaluwarsa
|
||||
return ['error' => true];
|
||||
}
|
||||
} catch (\Duitku\Exceptions\DuitkuException $e) {
|
||||
// Tangani pengecualian yang terkait dengan Duitku
|
||||
return ['error' => true, 'message' => $e->getMessage()];
|
||||
} catch (Exception $e) {
|
||||
// Tangani pengecualian umum
|
||||
return ['error' => true, 'message' => $e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
public static function createInvoice($data)
|
||||
{
|
||||
#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 = $data['paymentMethod']; // PaymentMethod list => https://docs.duitku.com/pop/id/#payment-method
|
||||
$paymentAmount = $data['paymentAmount']; // Amount
|
||||
$email = $data['email']; // your customer email
|
||||
$phoneNumber = $data['phoneNumber']; // your customer phone number (optional)
|
||||
$productDetails = $data['productDetails'];
|
||||
$merchantOrderId = $data['merchantOrderId']; // from merchant, unique
|
||||
$additionalParam = $data['additionalParam']; // optional
|
||||
$merchantUserInfo = $data['merchantUserInfo']; // optional
|
||||
$customerVaName = $data['customerVaName']; // display name on bank confirmation display
|
||||
$callbackUrl = env('DUITKU_PAYMENT_CALLBACK_URL'); // url for callback
|
||||
$returnUrl = env('APP_URL').'/api/linksehat/redirect-duitku';; // url for redirect
|
||||
$expiryPeriod = 60; // set the expired time in minutes
|
||||
|
||||
// Customer Detail
|
||||
$firstName = $data['firstName'];
|
||||
$lastName = $data['lastName'];
|
||||
|
||||
// Address
|
||||
$alamat = $data['alamat'];
|
||||
$city = $data['city'];
|
||||
$postalCode = $data['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 = self::configuration();
|
||||
try {
|
||||
// createInvoice Request
|
||||
$responseDuitkuPop = \Duitku\Pop::createInvoice($params, $duitkuConfig);
|
||||
header('Content-Type: application/json');
|
||||
return json_decode($responseDuitkuPop);
|
||||
} catch (Exception $e) {
|
||||
return json_decode($e->getMessage());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,6 +11,7 @@ use Illuminate\Support\Facades\DB;
|
||||
use App\Models\Member;
|
||||
use App\Models\User;
|
||||
use App\Models\Service;
|
||||
use App\Models\Icd;
|
||||
use DateTime;
|
||||
|
||||
class Helper
|
||||
@@ -117,6 +118,16 @@ class Helper
|
||||
}
|
||||
}
|
||||
|
||||
public static function diagnosisName($code)
|
||||
{
|
||||
$icd = Icd::where('code', $code)->get()->first();
|
||||
if ($icd){
|
||||
return $icd->name;
|
||||
} else {
|
||||
return '-';
|
||||
}
|
||||
}
|
||||
|
||||
public static function paginateResources($resource)
|
||||
{
|
||||
return [
|
||||
@@ -258,11 +269,14 @@ class Helper
|
||||
*
|
||||
* @param array|object $data
|
||||
* @param int $statusCode
|
||||
* @param string $message
|
||||
* @param string|array|object $message
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public static function responseJson(array|object $data = [], string $status = 'success', int $statusCode = Response::HTTP_OK, string $message = 'Data berhasil di ambil'): JsonResponse
|
||||
public static function responseJson(array|object $data = [], string $status = 'success', int $statusCode = Response::HTTP_OK, string|array|object $message = 'Data berhasil di ambil'): JsonResponse
|
||||
{
|
||||
if ($message instanceof \Illuminate\Support\MessageBag) {
|
||||
$message = $message->first();
|
||||
}
|
||||
return response()->json([
|
||||
'status' => $status,
|
||||
'statusCode' => $statusCode,
|
||||
@@ -377,9 +391,7 @@ class Helper
|
||||
$mail->send();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
dd($e);
|
||||
return ($mail->ErrorInfo);
|
||||
return false;
|
||||
return $mail->ErrorInfo;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -439,8 +451,52 @@ class Helper
|
||||
}
|
||||
} else {
|
||||
// throw new ImportRowException(__('Format Date Invalid'), 0, null, $date_from_row);
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static function calculateDistance($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo, $earthRadius = 6371) {
|
||||
// Convert degrees to radians
|
||||
$latFrom = deg2rad($latitudeFrom);
|
||||
$lonFrom = deg2rad($longitudeFrom);
|
||||
$latTo = deg2rad($latitudeTo);
|
||||
$lonTo = deg2rad($longitudeTo);
|
||||
|
||||
// Calculate the change in coordinates
|
||||
$deltaLat = $latTo - $latFrom;
|
||||
$deltaLon = $lonTo - $lonFrom;
|
||||
|
||||
// Apply Haversine formula
|
||||
$a = sin($deltaLat / 2) * sin($deltaLat / 2) + cos($latFrom) * cos($latTo) * sin($deltaLon / 2) * sin($deltaLon / 2);
|
||||
$c = 2 * atan2(sqrt($a), sqrt(1 - $a));
|
||||
$distance = $earthRadius * $c;
|
||||
|
||||
return $distance;
|
||||
}
|
||||
|
||||
public static function calculateAge($date_brith_day){
|
||||
// Konversi tanggal lahir ke dalam format UNIX timestamp
|
||||
$dob = strtotime($date_brith_day);
|
||||
|
||||
// Hitung umur berdasarkan tanggal lahir
|
||||
$umur = date('Y') - date('Y', $dob);
|
||||
|
||||
// Periksa apakah ulang tahun sudah lewat atau belum
|
||||
if (date('md', $dob) > date('md')) {
|
||||
$umur--;
|
||||
}
|
||||
|
||||
// Mengembalikan umur dalam format "x years old"
|
||||
return $umur . ' years old';
|
||||
}
|
||||
|
||||
public static function calculateDateDifference($startDate, $endDate)
|
||||
{
|
||||
$start = Carbon::parse($startDate);
|
||||
$end = Carbon::parse($endDate);
|
||||
|
||||
return $start->diffInDays($end) + 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user