api duitku dan profile add
This commit is contained in:
@@ -228,8 +228,50 @@ class LivechatController extends Controller
|
||||
}
|
||||
|
||||
public function consultation_payment(Request $request){
|
||||
|
||||
$livechat = Livechat::where('id', $request->consultation_id)->with(['doctor', 'practitioner'])->first();
|
||||
|
||||
$duitku = DuitkuHelper::paymentMethod();
|
||||
dd($duitku);
|
||||
$practitionerRole = PractitionerRole::where('id',$livechat->practitioner->id)->first();
|
||||
$price = $practitionerRole->price ? $practitionerRole->price : 30000;
|
||||
$adminFee = 5000;
|
||||
$discount = 0;
|
||||
$totalPay = $price + $adminFee - $discount;
|
||||
|
||||
// From database linksehat
|
||||
$user = User::with('detail')
|
||||
->where('nId', $livechat->patient_id)
|
||||
->first();
|
||||
|
||||
$data['paymentMethod'] = $request->payment_code;
|
||||
$data['paymentAmount'] = $totalPay;
|
||||
$data['email'] = $user->sEmail;
|
||||
$data['phoneNumber'] = $user->sPhone;
|
||||
$data['productDetails'] = $user->sEmail;
|
||||
$data['merchantOrderId'] = $livechat->uuid;
|
||||
$data['additionalParam'] = '';
|
||||
$data['merchantUserInfo'] = '';
|
||||
$data['customerVaName'] = $user->sFirstName . ' ' . $user->sLastName;
|
||||
$data['callbackUrl'] = 'htpps://google.com';
|
||||
$data['returnUrl'] = 'htpps://linksehat.com';
|
||||
$data['expiryPeriod'] = 60;
|
||||
$data['firstName'] = $user->sFirstName;
|
||||
$data['lastName'] = $user->sLastName;
|
||||
|
||||
// dd($user);
|
||||
$data['alamat'] = '';
|
||||
$data['city'] = '';
|
||||
$data['postalCode'] = '';
|
||||
|
||||
$duitku = DuitkuHelper::createInvoice($data);
|
||||
|
||||
return $duitku;
|
||||
}
|
||||
|
||||
public function consultation_check_payment($id){
|
||||
$livechat = Livechat::where('id',$id)->with(['doctor', 'practitioner'])->first();
|
||||
$duitku = DuitkuHelper::checkStatus($livechat->uuid);
|
||||
|
||||
return $duitku;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,46 @@ class ProfileController extends Controller
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
$validator = Validator::make($request->all(), [
|
||||
'id_user' => 'required',
|
||||
'first_name' => 'required',
|
||||
'last_name' => 'required',
|
||||
'date_of_birth' => 'required',
|
||||
// 'email' => 'required',
|
||||
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json(['errors' => $validator->errors()], 422);
|
||||
} else {
|
||||
$value = [
|
||||
'nIDuser' => $request->id_user,
|
||||
'sIPAddress' => $request->ip(),
|
||||
'sPassword' => null,
|
||||
'sFirstName' => $request->first_name,
|
||||
'sLastName' => $request->last_name,
|
||||
];
|
||||
|
||||
$user = User::create($value);
|
||||
$dataDetail = [
|
||||
'nIDUser' => $user->nID,
|
||||
'dTanggalLahir' => $request->date_of_birth,
|
||||
'nIDJenisKelamin' => $request->gender
|
||||
];
|
||||
|
||||
$userDetail = UserDetail::create(
|
||||
$dataDetail
|
||||
);
|
||||
|
||||
$data['data'] = [
|
||||
'status' => 200,
|
||||
'message' => 'data berhasil di tambahkan',
|
||||
'error' => 'false'
|
||||
|
||||
];
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -70,6 +70,7 @@ Route::prefix('linksehat')->group(function () {
|
||||
Route::get('profile/{id}', [ProfileController::class, 'index'])->name('profile');
|
||||
Route::get('change-profile/{id}', [ProfileController::class, 'changeProfile'])->name('change-profile');
|
||||
Route::post('profile', [ProfileController::class, 'update'])->name('profile.update');
|
||||
Route::post('profile-add', [ProfileController::class, 'store'])->name('profile.store');
|
||||
Route::post('notification-tokens/delete/{id}', [NotificationTokenController::class, 'destroy'])->name('profile.delete.token');
|
||||
Route::post('notification-tokens', [NotificationTokenController::class, 'store'])->name('profile.store.token');
|
||||
Route::apiResource('appointment', AppointmentController::class);
|
||||
@@ -95,7 +96,8 @@ Route::prefix('linksehat')->group(function () {
|
||||
Route::get('livechat/consultation', 'consultation')->name('livechats.consultation');
|
||||
Route::post('livechat/consultation-request', 'consultation_request')->name('livechats.consultation-request');
|
||||
Route::get('livechat/consultation-request/{id}', 'consultation_request_show');
|
||||
Route::get('livechat/consultation-request/consultation_payment_choose/{id}', 'consultation_payment_choose');
|
||||
Route::get('livechat/consultation-request/consultation-payment-choose/{id}', 'consultation_payment_choose');
|
||||
Route::get('livechat/consultation-request/consultation-payment-check/{id}', 'consultation_check_payment');
|
||||
|
||||
Route::post('livechat/consultation-payment', 'consultation_payment');
|
||||
});
|
||||
|
||||
@@ -30,4 +30,140 @@ class DuitkuHelper
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public static function checkStatus($merchantOrderId)
|
||||
{
|
||||
$duitkuConfig = self::configuration();
|
||||
$data = [
|
||||
'merchantOrderId' => $merchantOrderId
|
||||
];
|
||||
try {
|
||||
$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
|
||||
}
|
||||
return $transaction;
|
||||
// return json_decode($transaction);
|
||||
} catch (Exception $e) {
|
||||
return $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('APP_URL').'/api/linksehat/callback-duitku'; // 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());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -38,6 +38,7 @@ class User extends Authenticatable
|
||||
'sEmail',
|
||||
'nIDHubunganKeluarga',
|
||||
'dUpdateOn',
|
||||
'sIPAddress',
|
||||
];
|
||||
|
||||
protected function fullName(): Attribute
|
||||
|
||||
Reference in New Issue
Block a user