PaymentController
extends Controller
in package
Class PaymentController
- Handles the checkout process, payment simulation, and order finalization
- Transforms temporary cart items into permanent database records (orders & mosaics)
Table of Contents
Properties
- $trans : array<string|int, mixed>
- $paypalBaseUrl : string
- $translations : array<string|int, mixed>
Methods
- __construct() : mixed
- Constructor.
- cancel() : void
- Handles cases where the user aborts the payment process at paypal
- confirmation() : void
- Displays the final invoice and breakdown of costs after a successful purchase
- index() : void
- Displays the checkout page with cart summary and shipping details
- process() : void
- Initiates the paypal payment flow by creating an order and redirecting the user
- render() : void
- Renders a view file within a layout template.
- success() : void
- Handles the callback from paypal after user approval
- callPayPalApi() : object
- Helper to execute curl requests against paypal api
- finalizeOrder() : void
- Persists the order to the database, generates final mosaic files, and updates stock
- getPayPalAccessToken() : string|null
- Retrieves a new oauth2 access token from paypal
- sendInvoiceEmail() : void
- Generates and dispatches the html receipt via smtp
Properties
$trans
protected
array<string|int, mixed>
$trans
= []
Holds translation strings for the current language.
$paypalBaseUrl
private
string
$paypalBaseUrl
= 'https://api-m.sandbox.paypal.com'
Base URL for PayPal API (Sandbox).
$translations
private
array<string|int, mixed>
$translations
Key/Value pair of translations.
Methods
__construct()
Constructor.
public
__construct() : mixed
Initializes the controller and loads translation strings
cancel()
Handles cases where the user aborts the payment process at paypal
public
cancel() : void
confirmation()
Displays the final invoice and breakdown of costs after a successful purchase
public
confirmation() : void
index()
Displays the checkout page with cart summary and shipping details
public
index() : void
process()
Initiates the paypal payment flow by creating an order and redirecting the user
public
process() : void
render()
Renders a view file within a layout template.
public
render(string $file[, array<string|int, mixed> $data = [] ][, string $template = 'default' ]) : void
Parameters
- $file : string
-
The name of the view file (without .php extension).
- $data : array<string|int, mixed> = []
-
Associative array of data to pass to the view.
- $template : string = 'default'
-
The layout template to use (default: 'default').
success()
Handles the callback from paypal after user approval
public
success() : void
callPayPalApi()
Helper to execute curl requests against paypal api
private
callPayPalApi(string $endpoint, mixed $postData, string $token) : object
Parameters
- $endpoint : string
-
api endpoint path
- $postData : mixed
-
data payload
- $token : string
-
auth token
Return values
object —response data
finalizeOrder()
Persists the order to the database, generates final mosaic files, and updates stock
private
finalizeOrder(object $paypalData) : void
Parameters
- $paypalData : object
-
response data from paypal api
getPayPalAccessToken()
Retrieves a new oauth2 access token from paypal
private
getPayPalAccessToken() : string|null
Return values
string|null —access token
sendInvoiceEmail()
Generates and dispatches the html receipt via smtp
private
sendInvoiceEmail(string $email, array<string|int, mixed> $order) : void
Parameters
- $email : string
-
recipient address
- $order : array<string|int, mixed>
-
order details