0% found this document useful (0 votes)
17 views10 pages

Untitled Presentation

The document describes setting up a payment notification system in Laravel. It includes steps to install Laravel, create a database migration, configure mail settings, build a payment form, controller, routes, model and notification class.

Uploaded by

budi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views10 pages

Untitled Presentation

The document describes setting up a payment notification system in Laravel. It includes steps to install Laravel, create a database migration, configure mail settings, build a payment form, controller, routes, model and notification class.

Uploaded by

budi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Mail Payment

Laravel

Jofan Fathurahman
Data Diri

Nama : Jofan Fathurahman


Kelas : 20TIA4
Kejuruan : IoT
Tepat Tinggal : Klaten
Langkah - Langkah

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

<! DOCTYPE html >


<html >

<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

<div class ="form-group" >


<label for ="amount" >Amount: </ label >
<input type ="number" class ="form-control" id ="amount" name ="amount" required >
</ div >

<div class ="form-group" >


<label for ="email" >Email: </ label >
<input type ="email" class ="form-control" id ="email" name ="email" required >
</ div >

<button type ="submit" class ="btn btn-primary" >Submit Payment </ button >
</ form >
</ div >
</ div >
</ div >

<!-- Tambahkan script Bootstrap dan jQuery -->


<script src ="https://code.jquery.com/jquery-3.5.1.slim.min.js" ></ script >
<script src ="https://cdn.jsdelivr.net/npm/ @popperjs /[email protected]/dist/umd/popper.min.js" ></ script >
<script src ="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" ></ script >
</ body >

</ html >


Halaman Contrroler

<?php

namespace App\Http\Controllers ;

use Illuminate\Http\ Request ;


use App\Models\ Payment ;
use App\Models\ User ;
use App\Notifications\ PaymentConfirmationNotification ;

class PaymentController extends Controller


{
public function showPaymentForm ()
{
return view ('payment_form' );
}

public function processPayment (Request $request )


{

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

use Illuminate\Support\Facades\ Route ;


use App\Http\Controllers\ Home ;
use App\Http\Controllers\ PaymentController ;

/*
|--------------------------------------------------------------------------
| 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 ('/' , function () {


return view ('welcome' );
});

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 ;

use Illuminate\Database\Eloquent\Factories\ HasFactory ;


use Illuminate\Database\Eloquent\ Model;

class Payment extends Model


{
use HasFactory ;

protected $fillable = ['order_id' , 'amount' , 'is_success' ];


}
Migrations

Schema::create('payments', function (Blueprint $table) {


$table->id();
$table->string('order_id');
$table->decimal('amount', 10, 2);
$table->boolean('is_success')->default(false);
$table->timestamps();
});
Halaman Notifkacations

<?php

namespace App\Notifications ;

use Illuminate\Bus\ Queueable ;


use Illuminate\Contracts\Queue\ ShouldQueue ;
use Illuminate\Notifications\Messages\ MailMessage ;
use Illuminate\Notifications\ Notification ;

class PaymentConfirmationNotification extends Notification


{
use Queueable ;

/**
* 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 [
//
];
}
}

You might also like