Skip to content

Commit 3c04eef

Browse files
committed
Add stripe new tests from main
1 parent 31292ca commit 3c04eef

5 files changed

Lines changed: 96 additions & 0 deletions

File tree

utils/build/docker/php/weblogs/laravel11x/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"php": "^8.2",
66
"laravel/framework": "^11.0",
77
"laravel/tinker": "^2.9",
8+
"stripe/stripe-php": "^10.0",
89
"weblog/acme": "*"
910
},
1011
"repositories": [

utils/build/docker/php/weblogs/laravel11x/routes/web.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,3 +694,41 @@
694694
$acme = new \Acme\Acme();
695695
return response('ok', 200, ['Content-Type' => 'text/plain']);
696696
});
697+
698+
Route::post('/stripe/create_checkout_session', function (Request $request) {
699+
\Stripe\Stripe::setApiKey('sk_FAKE');
700+
\Stripe\Stripe::$apiBase = 'http://internal_server:8089';
701+
702+
try {
703+
$result = \Stripe\Checkout\Session::create($request->json()->all());
704+
return response(json_encode($result), 200, ['Content-Type' => 'application/json']);
705+
} catch (\Throwable $e) {
706+
return response(json_encode(['error' => $e->getMessage()]), 500, ['Content-Type' => 'application/json']);
707+
}
708+
});
709+
710+
Route::post('/stripe/create_payment_intent', function (Request $request) {
711+
\Stripe\Stripe::setApiKey('sk_FAKE');
712+
\Stripe\Stripe::$apiBase = 'http://internal_server:8089';
713+
714+
try {
715+
$result = \Stripe\PaymentIntent::create($request->json()->all());
716+
return response(json_encode($result), 200, ['Content-Type' => 'application/json']);
717+
} catch (\Throwable $e) {
718+
return response(json_encode(['error' => $e->getMessage()]), 500, ['Content-Type' => 'application/json']);
719+
}
720+
});
721+
722+
Route::post('/stripe/webhook', function (Request $request) {
723+
\Stripe\Stripe::setApiKey('sk_FAKE');
724+
725+
$payload = $request->getContent();
726+
$sigHeader = $request->header('Stripe-Signature', '');
727+
728+
try {
729+
$event = \Stripe\Webhook::constructEvent($payload, $sigHeader, 'whsec_FAKE');
730+
return response(json_encode($event->data->object), 200, ['Content-Type' => 'application/json']);
731+
} catch (\Throwable $e) {
732+
return response(json_encode(['error' => $e->getMessage()]), 403, ['Content-Type' => 'application/json']);
733+
}
734+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
require_once __DIR__ . '/vendor/autoload.php';
4+
5+
header('Content-Type: application/json');
6+
7+
\Stripe\Stripe::setApiKey('sk_FAKE');
8+
\Stripe\Stripe::$apiBase = 'http://internal_server:8089';
9+
10+
$body = json_decode(file_get_contents('php://input'), true) ?? [];
11+
12+
try {
13+
$result = \Stripe\Checkout\Session::create($body);
14+
echo json_encode($result);
15+
} catch (\Exception $e) {
16+
http_response_code(500);
17+
echo json_encode(['error' => $e->getMessage()]);
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
require_once __DIR__ . '/vendor/autoload.php';
4+
5+
header('Content-Type: application/json');
6+
7+
\Stripe\Stripe::setApiKey('sk_FAKE');
8+
\Stripe\Stripe::$apiBase = 'http://internal_server:8089';
9+
10+
$body = json_decode(file_get_contents('php://input'), true) ?? [];
11+
12+
try {
13+
$result = \Stripe\PaymentIntent::create($body);
14+
echo json_encode($result);
15+
} catch (\Exception $e) {
16+
http_response_code(500);
17+
echo json_encode(['error' => $e->getMessage()]);
18+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
require_once __DIR__ . '/vendor/autoload.php';
4+
5+
header('Content-Type: application/json');
6+
7+
\Stripe\Stripe::setApiKey('sk_FAKE');
8+
9+
$payload = file_get_contents('php://input');
10+
$sigHeader = $_SERVER['HTTP_STRIPE_SIGNATURE'] ?? '';
11+
12+
try {
13+
$event = \Stripe\Webhook::constructEvent($payload, $sigHeader, 'whsec_FAKE');
14+
echo json_encode($event->data->object);
15+
} catch (\Stripe\Exception\SignatureVerificationException $e) {
16+
http_response_code(403);
17+
echo json_encode(['error' => $e->getMessage()]);
18+
} catch (\Exception $e) {
19+
http_response_code(403);
20+
echo json_encode(['error' => $e->getMessage()]);
21+
}

0 commit comments

Comments
 (0)