Untitled Presentation
Untitled Presentation
Laravel
Jofan Fathurahman
Data Diri
1. Instalasi Laravel
composer create-project laravel/laravel Payments
2. Migrate Database
php artisan make:migration create_payments_table
--create=payments
3. Env Mail
4. Buat Contrroler dan Model & Notifikasi
php artisan make:model Payment
php artisan make:controller PaymentController
php artisan make:notification
PaymentConfirmationNotification
Halaman ENV
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD={isi dengan password anda}
MAIL_ENCRYPTION=tls
[email protected]
MAIL_FROM_NAME="${APP_NAME}"
Halaman Form
<head >
<title >Payment Form </ title >
<!-- Tambahkan link Bootstrap CSS -->
<link rel ="stylesheet" href ="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" >
</ head >
<body >
<div class ="container mt-5" >
<div class ="row justify-content-center" >
<div class ="col-md-6" >
<h1 >Contoh Payment </ h1 >
<!-- Form -->
<form id ="payment-form" action ="{{ url ('/payment/process') }} " method ="POST" >
@csrf
<button type ="submit" class ="btn btn-primary" >Submit Payment </ button >
</ form >
</ div >
</ div >
</ div >
<?php
namespace App\Http\Controllers ;
User :: create ([
'email' => $request -> email
]);
$user = User :: where ('email' , $request -> input ('email' ))-> first ();
// Simulasi pembayaran
Payment :: create ([
'order_id' => 'ORDER-' . time (),
'amount' => $request -> amount , // Ganti dengan jumlah pembayaran sesuai kebutuhan
'is_success' => true ,
]);
$user -> notify (new PaymentConfirmationNotification ());
return 'Sukses' ;
}
}
Halaman Routes
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/
Route :: get (
'/payment' ,
[ PaymentController :: class , 'showPaymentForm' ]
)-> name ('showPaymentForm' );
Route :: post (
'/payment/process' ,
[ PaymentController :: class , 'processPayment' ]
)-> name ('processPayment' );
Route :: get (
'/payment/finish' ,
[ PaymentController :: class , 'finishPayment' ]
)-> name ('finish' );
Halaman Model
<?php
namespace App\Models ;
<?php
namespace App\Notifications ;
/**
* Create a new notification instance.
*/
public function __construct ()
{
//
}
/**
* Get the notification's delivery channels.
*
* @return array <int , string>
*/
public function via (object $notifiable ): array
{
return [ 'mail' ];
}
/**
* Get the mail representation of the notification.
*/
public function toMail ($notifiable ): MailMessage
{
return ( new MailMessage )
-> subject ('Pemberitahuan Pembayaran' )
-> line ('Terima kasih atas pesanan Anda.' )
-> line ('Mohon untuk segera melakukan pembayaran.' )
// ->line('Laporan: ' . $notifiable->laporan) // Tambahkan baris laporan
-> action ('Konfirmasi Pembayaran' , url ('/payment/' . $notifiable -> cek ))
-> line ('Jika sudah melakukan pembayaran, abaikan pesan ini.' )
-> line ('Terima kasih atas dukungan Anda.' );
}
/**
* Get the array representation of the notification.
*
* @return array <string , mixed>
*/
public function toArray (object $notifiable ): array
{
return [
//
];
}
}