Skip to content

Commit 69acdf8

Browse files
committed
Update built-in routes, and clean up code
1 parent 3c0b4dd commit 69acdf8

File tree

10 files changed

+75
-31
lines changed

10 files changed

+75
-31
lines changed

resources/views/checkout.blade.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,10 +500,6 @@ function chargeCard(auth_id, card_token) {
500500
console.log('Executing payment...');
501501
console.log('Authentication ID: ' + auth_id)
502502
503-
// const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content')
504-
505-
// Make a POST request to the endpoint you specified where the
506-
// Xendivel::makePayment() will be executed.
507503
axios.post('/pay-with-card', {
508504
amount: document.getElementById('amount-to-pay').value,
509505
token_id: card_token,

routes/xendivel-routes.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use App\Events\eWalletEvents;
44
use GlennRaya\Xendivel\Invoice;
5+
use GlennRaya\Xendivel\Xendivel;
56
use Illuminate\Http\Request;
67
use Illuminate\Support\Facades\Route;
78

@@ -107,6 +108,55 @@
107108
return Invoice::make($invoice_data)
108109
->download();
109110
});
111+
112+
// Example card charge, then send invoice to email as an attachment.
113+
Route::post('/pay-with-card', function (Request $request) {
114+
$payment = Xendivel::payWithCard($request)
115+
->getResponse();
116+
117+
return $payment;
118+
});
119+
120+
// Example card charge, then send invoice to email as an attachment.
121+
Route::post('/pay-with-card-email-invoice', function (Request $request) {
122+
$invoice_data = [
123+
'invoice_number' => 1000023,
124+
'card_type' => 'VISA',
125+
'masked_card_number' => '400000XXXXXX0002',
126+
'merchant' => [
127+
'name' => 'Stark Industries',
128+
'address' => '152 Maple Avenue Greenfield, New Liberty, Arcadia USA 54331',
129+
'phone' => '+63 971-444-1234',
130+
'email' => 'xendivel@example.com',
131+
],
132+
'customer' => [
133+
'name' => 'Mr. Glenn Raya',
134+
'address' => 'Alex Johnson, 4457 Pine Circle, Rivertown, Westhaven, 98765, Silverland',
135+
'email' => 'victoria@example.com',
136+
'phone' => '+63 909-098-654',
137+
],
138+
'items' => [
139+
['item' => 'MacBook Pro 16" M3 Max', 'price' => $request->amount, 'quantity' => 1],
140+
],
141+
'tax_rate' => .12,
142+
'tax_id' => '123-456-789',
143+
'footer_note' => 'Thank you for your recent purchase with us! We are thrilled to have the opportunity to serve you and hope that your new purchase brings you great satisfaction.',
144+
];
145+
146+
$payment = Xendivel::payWithCard($request)
147+
->emailInvoiceTo('glenn@example.com', $invoice_data)
148+
->send()
149+
->getResponse();
150+
151+
return $payment;
152+
});
153+
154+
Route::post('/pay-via-ewallet', function (Request $request) {
155+
$payment = Xendivel::payWithEWallet($request)
156+
->getResponse();
157+
158+
return $payment;
159+
});
110160
}
111161

112162
// Listen to webhook events from Xendit. This will fire up an event listener

src/Concerns/InvoicePathResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ trait InvoicePathResolver
1111
* It will provide a default if none is provided.
1212
*
1313
* @param string $filename Required. The filename of the invoice.
14-
* @return string Returns the PDF filename and the full path where the invoice was stored.
14+
* @return string Returns the PDF filename and the full path where the invoice was stored.
1515
*
1616
* @throws Exception
1717
*/

src/Invoice.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class Invoice
2727
/**
2828
* Generate the invoice and save it to storage.
2929
*
30-
* @param array $invoice_data [required] The associative array of information to be displayed on the invoice.
31-
* @param string $filename [optional] The filename of the invoice. Will defaults to UUID v4 filename.
32-
* @param string $template [optional] The invoice blade template file.
30+
* @param array $invoice_data [required] The associative array of information to be displayed on the invoice.
31+
* @param string $filename [optional] The filename of the invoice. Will defaults to UUID v4 filename.
32+
* @param string $template [optional] The invoice blade template file.
3333
*/
3434
public static function make(array $invoice_data)
3535
{
@@ -75,7 +75,7 @@ public static function make(array $invoice_data)
7575
* will be deleted from storage, thereby saving
7676
* some space on the disk.
7777
*
78-
* @throws Exception if the file does not exists.
78+
* @throws Exception if the file does not exists.
7979
*/
8080
public function download(): BinaryFileResponse
8181
{
@@ -108,7 +108,7 @@ public function download(): BinaryFileResponse
108108
/**
109109
* Specify a different template for the invoice.
110110
*
111-
* @param string|null $template [optional] The filename for the invoice template.
111+
* @param string|null $template [optional] The filename for the invoice template.
112112
*/
113113
public function template(?string $template = null): self
114114
{

src/Mail/InvoicePaid.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class InvoicePaid extends Mailable
1818
/**
1919
* Create a new message instance.
2020
*
21-
* @param GlennRaya\Xendivel\Invoice $invoice_pdf [required] The invoice PDF.
22-
* @param mixed|null $subject [optional] The subject of the email.
23-
* @param mixed|null $message [optional] The email message.
21+
* @param GlennRaya\Xendivel\Invoice $invoice_pdf [required] The invoice PDF.
22+
* @param mixed|null $subject [optional] The subject of the email.
23+
* @param mixed|null $message [optional] The email message.
2424
* @return void
2525
*/
2626
public function __construct(protected $invoice_pdf, public $subject = null, public $message = null)

src/Mail/RefundConfirmation.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class RefundConfirmation extends Mailable
1616
/**
1717
* Create a new message instance.
1818
*
19-
* @param mixed|null $subject [optional] The subject of the email.
20-
* @param mixed|null $message [optional] The email message.
19+
* @param mixed|null $subject [optional] The subject of the email.
20+
* @param mixed|null $message [optional] The email message.
2121
* @return void
2222
*/
2323
public function __construct(public $subject = null, public $message = null)

src/XenditApi.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ private static function generateAuthToken(): string
2727
/**
2828
* Perform Xendit API call.
2929
*
30-
* @param string $method [required] The type of HTTP request (post, get, etc).
31-
* @param string $uri [required] The URI for the request.
32-
* @param array $payload [required] The request payload for the API.
30+
* @param string $method [required] The type of HTTP request (post, get, etc).
31+
* @param string $uri [required] The URI for the request.
32+
* @param array $payload [required] The request payload for the API.
3333
*
3434
* @throws Exception
3535
*/

src/Xendivel.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class Xendivel extends XenditApi
7272
/**
7373
* Make a payment request with the tokenized value of the card.
7474
*
75-
* @param Illuminate\Http\Requests $payload [required] The tokenized data of the card and other data.
75+
* @param Illuminate\Http\Requests $payload [required] The tokenized data of the card and other data.
7676
*/
7777
public static function payWithCard($payload): self
7878
{
@@ -118,8 +118,8 @@ public static function payWithCard($payload): self
118118
/**
119119
* Get the card or ewallet charge transaction by charge id.
120120
*
121-
* @param string $charge_id [required] The charge ID of the of the payment (card or ewallet).
122-
* @param string $charge_type [required] The type of payment method. Either card or ewallet.
121+
* @param string $charge_id [required] The charge ID of the of the payment (card or ewallet).
122+
* @param string $charge_type [required] The type of payment method. Either card or ewallet.
123123
*/
124124
public static function getPayment(string $id, string $charge_type): self
125125
{
@@ -141,8 +141,8 @@ public static function getPayment(string $id, string $charge_type): self
141141
/**
142142
* Get the status and details of a specific eWallet refund by its refund ID.
143143
*
144-
* @param string $charge_id [required] The ID of the eWallet charge.
145-
* @param string $refund_id [required] The ID of the eWallet refund.
144+
* @param string $charge_id [required] The ID of the eWallet charge.
145+
* @param string $refund_id [required] The ID of the eWallet refund.
146146
*/
147147
public static function getEwalletRefund(string $charge_id, string $refund_id): self
148148
{
@@ -158,7 +158,7 @@ public static function getEwalletRefund(string $charge_id, string $refund_id): s
158158
/**
159159
* Get the details of all eWallet refunds associated with a single eWallet charge identified by charge ID.
160160
*
161-
* @param string $charge_id [required] The eWallet charge ID.
161+
* @param string $charge_id [required] The eWallet charge ID.
162162
*/
163163
public static function getListOfEwalletRefunds(string $charge_id): self
164164
{
@@ -195,9 +195,9 @@ public static function payWithEwallet($payload): self
195195
/**
196196
* Request for a refund. Currently for cards and ewallet charge type.
197197
*
198-
* @param int $amount [required] The amount to be refunded. Can be partial amount.
199-
* @param string $id [optional] The external id provided by the user or auto provided.
200-
* @param string $reason [optional] The reason for the refund.
198+
* @param int $amount [required] The amount to be refunded. Can be partial amount.
199+
* @param string $id [optional] The external id provided by the user or auto provided.
200+
* @param string $reason [optional] The reason for the refund.
201201
*/
202202
public function refund(int $amount, ?string $id = null, ?string $reason = 'OTHERS'): self
203203
{
@@ -242,7 +242,7 @@ public function refund(int $amount, ?string $id = null, ?string $reason = 'OTHER
242242
/**
243243
* Void eWallet charge.
244244
*
245-
* @param string $id [required] The ID of the eWallet charge.
245+
* @param string $id [required] The ID of the eWallet charge.
246246
*/
247247
public static function void(string $id): self
248248
{
@@ -337,7 +337,7 @@ public function send(): self
337337
/**
338338
* Send refund confirmation e-mail to customer.
339339
*
340-
* @param string $email [required] The email address where the confirmation will be sent.
340+
* @param string $email [required] The email address where the confirmation will be sent.
341341
*/
342342
public function emailRefundConfirmationTo(string $email): self
343343
{

tests/Feature/XendivelFeatureTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
use GlennRaya\Xendivel\Xendivel;
43
use Tests\TestCase;
54

65
uses(TestCase::class);

tests/TestCase.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@ protected function getPackageProviders($app)
1515
\GlennRaya\Xendivel\XendivelServiceProvider::class,
1616
];
1717
}
18-
1918
}

0 commit comments

Comments
 (0)