Skip to content

Commit

Permalink
Merge pull request #192 from Naoray/feature/make-order-translatable
Browse files Browse the repository at this point in the history
Makes Payment description and Receipt translatable
  • Loading branch information
Naoray committed Sep 14, 2023
2 parents 0710aac + 2e65450 commit 3f78f3c
Show file tree
Hide file tree
Showing 6 changed files with 248 additions and 182 deletions.
5 changes: 5 additions & 0 deletions resources/lang/en/payment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'description' => 'Order :number',
];
12 changes: 12 additions & 0 deletions resources/lang/en/receipt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

return [
'balance_after' => 'Balance after',
'balance_applied' => 'Balance applied',
'balance_before' => 'Balance before',
'details_title' => 'Your details',
'subtotal' => 'Subtotal',
'title' => 'Your receipt',
'total_due' => 'Total due',
'vat' => 'VAT',
];
386 changes: 210 additions & 176 deletions resources/views/receipt.blade.php

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions src/Order/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Invoice
use FormatsAmount;

const DEFAULT_VIEW = 'cashier::receipt';
const DEFAULT_DATE_FORMAT = 'MMM D, Y';

/**
* The invoice id. Also know as "reference".
Expand Down Expand Up @@ -141,6 +142,11 @@ public function setDate(Carbon $date)
return $this;
}

public function isoFormattedDate(): string
{
return $this->date->isoFormat(static::DEFAULT_DATE_FORMAT);
}

/**
* @param \Laravel\Cashier\Order\Contracts\InvoicableItem $item
* @return $this
Expand Down Expand Up @@ -457,7 +463,7 @@ public function view(array $data = [], string $view = self::DEFAULT_VIEW)
*/
public function pdf(array $data = [], string $view = self::DEFAULT_VIEW, Options $options = null)
{
if (! defined('DOMPDF_ENABLE_AUTOLOAD')) {
if (!defined('DOMPDF_ENABLE_AUTOLOAD')) {
define('DOMPDF_ENABLE_AUTOLOAD', false);
}

Expand All @@ -481,11 +487,11 @@ public function download(array $data = [], string $view = self::DEFAULT_VIEW, Op
$filename = implode('_', [
$this->id,
Str::snake(config('app.name', '')),
]).'.pdf';
]) . '.pdf';

return new Response($this->pdf($data, $view, $options), 200, [
'Content-Description' => 'File Transfer',
'Content-Disposition' => 'attachment; filename="'.$filename.'"',
'Content-Disposition' => 'attachment; filename="' . $filename . '"',
'Content-Transfer-Encoding' => 'binary',
'Content-Type' => 'application/pdf',
]);
Expand All @@ -496,7 +502,7 @@ public function download(array $data = [], string $view = self::DEFAULT_VIEW, Op
*/
public function hasStartingBalance()
{
return ! $this->rawStartingBalance()->isZero();
return !$this->rawStartingBalance()->isZero();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Order/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,9 @@ public function processPayment()

case $totalDue->greaterThanOrEqual($minimumPaymentAmount):

// Create Mollie payment
$payment = (new MandatedPaymentBuilder(
$owner,
'Order ' . $this->number,
trans('cashier::payment.description', ['number' => $this->number], Cashier::getLocale($owner)),
$totalDue,
url(config('cashier.webhook_url')),
[
Expand Down
10 changes: 10 additions & 0 deletions tests/Order/InvoiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ public function canSetDate()
$this->assertCarbon($now->addYears(2), $invoice->date());
}

/** @test */
public function canReceiveDateInDifferentLanguages()
{
$invoice = new Invoice('EUR', null, Carbon::parse('May 15 2023'));
$this->assertEquals('May 15, 2023', $invoice->isoFormattedDate());

Carbon::setLocale('de');
$this->assertEquals('Mai 15, 2023', $invoice->isoFormattedDate());
}

/** @test */
public function canAddExtraInformation()
{
Expand Down

0 comments on commit 3f78f3c

Please sign in to comment.