'https://mss.cpc.getswish.net', 'app.swish_payee_alias' => '1231181189', 'app.swish_callback_url' => 'https://swish.example.se/webhook/swish', ]); } /** * Stand in for the Swish API. Without a queued response the controller would * make a real call, so every test that reaches it has to set this up. */ protected function fakeSwish(GuzzleResponse $response): void { $stack = HandlerStack::create(new MockHandler([$response])); $stack->push(Middleware::history($this->swishRequests)); $this->app->instance(Client::class, new Client(['handler' => $stack])); } protected function fakeSwishAcceptsWithToken(string $token = 'TOKEN123'): void { $this->fakeSwish(new GuzzleResponse(201, ['PaymentRequestToken' => $token])); } /** The JSON body of the last request sent to Swish */ protected function lastSwishBody(): array { $request = end($this->swishRequests)['request']; return json_decode((string) $request->getBody(), true); } protected function customer(array $attributes = []): Customer { $customer = new Customer(); // forceFill because the model's $fillable spells amount_left with a space $customer->forceFill(array_merge([ 'lan_id' => 1, 'name' => 'Erik Olsson', 'guardian_name' => 'VÄrdnadshavare', 'deposit' => 0, 'amount_left' => 0, 'give_leftover' => 0, 'is_in_group' => 0, ], $attributes))->save(); return $customer; } protected function transaction(array $attributes = []): Transaction { return Transaction::create(array_merge([ 'payment_reference' => 'LAN-TEST0001', 'customer_id' => 1, 'expected_amount' => 100, 'status' => 'pending', 'give_leftover' => 0, 'source' => 'kiosk', 'instruction_uuid' => 'AB23D7406ECE4542A80152D909EF9F6B', 'callback_identifier' => 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', ], $attributes)); } /** * Post a callback the way Swish would, with the identifier as a header. */ protected function postCallback(array $payload, ?string $identifier = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee') { $headers = $identifier === null ? [] : ['callbackIdentifier' => $identifier]; return $this->postJson('/api/swish', $payload, $headers); } protected function paidPayload(array $overrides = []): array { return array_merge([ 'id' => 'AB23D7406ECE4542A80152D909EF9F6B', 'payeePaymentReference' => 'LAN-TEST0001', 'paymentReference' => '6D6CD7406ECE4542A80152D909EF9F6B', 'payerAlias' => '46701234567', 'payeeAlias' => '1231181189', 'amount' => 100, 'currency' => 'SEK', 'message' => 'vBytes LAN', 'status' => 'PAID', 'errorCode' => null, 'errorMessage' => '', ], $overrides); } }