File tree Expand file tree Collapse file tree 3 files changed +71
-0
lines changed
tests/api/Feature/Domain/Cart/JsonApi/V1 Expand file tree Collapse file tree 3 files changed +71
-0
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,9 @@ public function checkout(
4343 'product_lines ' ,
4444 'product_lines.purchasable ' ,
4545 ])
46+ ->withMeta ([
47+ 'order_signature ' => $ order ->getSelfLinkSignature (),
48+ ])
4649 ->didCreate ();
4750 }
4851}
Original file line number Diff line number Diff line change 88use Illuminate \Database \Eloquent \Relations \HasMany ;
99use Illuminate \Database \Eloquent \Relations \HasOne ;
1010use Illuminate \Support \Facades \Config ;
11+ use Illuminate \Support \Facades \URL ;
1112use Lunar \Base \Casts \Price ;
1213use Lunar \Models \Transaction ;
1314
1415trait InteractsWithDystoreApi
1516{
1617 use HashesRouteKey;
1718
19+ public function getSelfLinkSignature (): ?string
20+ {
21+ $ signedUrl = URL ::signedRoute (
22+ name: 'v1.orders.show ' ,
23+ parameters: ['order ' => $ this ->getRouteKey ()],
24+ absolute: false ,
25+ );
26+
27+ $ signature = null ;
28+
29+ $ query = (string ) parse_url ($ signedUrl , PHP_URL_QUERY );
30+ if ($ query !== '' ) {
31+ /** @var array<string, mixed> $params */
32+ parse_str ($ query , $ params );
33+ $ signature = is_string ($ params ['signature ' ] ?? null ) ? $ params ['signature ' ] : null ;
34+ }
35+
36+ return $ signature ;
37+ }
38+
1839 /**
1940 * Attribute activity log blacklist.
2041 *
Original file line number Diff line number Diff line change 430430 ]
431431 );
432432});
433+
434+ it ('returns order signature in meta after checkout ' , function () {
435+ /** @var TestCase $this */
436+ Config::set ('dystore.general.checkout.checkout_protection_strategy ' , CheckoutProtectionStrategy::SIGNATURE );
437+
438+ /** @var CartFactory $factory */
439+ $ factory = Cart::factory ();
440+
441+ /** @var Cart $cart */
442+ $ cart = $ factory
443+ ->withAddresses ()
444+ ->withLines ()
445+ ->create ();
446+
447+ /** @var CartSessionManager $cartSession */
448+ $ cartSession = App::make (CartSessionInterface::class);
449+ $ cartSession ->use ($ cart );
450+
451+ $ response = $ this
452+ ->jsonApi ()
453+ ->expects ('orders ' )
454+ ->withData ([
455+ 'type ' => 'carts ' ,
456+ 'attributes ' => [
457+ 'agree ' => true ,
458+ 'create_user ' => false ,
459+ ],
460+ ])
461+ ->post (serverUrl ('/carts/-actions/checkout ' ));
462+
463+ $ orderId = $ response ->json ('data.id ' );
464+
465+ ray ($ response ->json ('meta.order_signature ' ));
466+
467+ $ response
468+ ->assertSuccessful ()
469+ ->assertCreatedWithServerId (
470+ serverUrl ('/orders ' , true ),
471+ [
472+ 'type ' => 'orders ' ,
473+ 'id ' => (string ) $ response ->json ('data.id ' ),
474+ ]
475+ )
476+ ->assertMeta ([
477+ 'order_signature ' => $ response ->json ('meta.order_signature ' ),
478+ ]);
479+ });
You can’t perform that action at this time.
0 commit comments