'Max', 'cc_cardholder_last' => 'Mustermann', 'cc_cardpan' => '4111111111111111', 'cc_cardexpiremonth' => '12', 'cc_cardexpireyear' => '2030', 'cc_cardtype' => 'V', 'cc_cardcvc2' => '123', ], $override); } it('maps form data to the cc_* keys the payment service expects', function () { $dto = CreditCardCheckData::fromFormData(validCardForm()); expect($dto)->toBeInstanceOf(CreditCardCheckData::class) ->and($dto->cardPan)->toBe('4111111111111111') ->and($dto->cardType)->toBe('V'); expect($dto->toCheckArray())->toBe([ 'cc_cardholder_first' => 'Max', 'cc_cardholder_last' => 'Mustermann', 'cc_cardpan' => '4111111111111111', 'cc_cardexpiremonth' => '12', 'cc_cardexpireyear' => '2030', 'cc_cardtype' => 'V', 'cc_cardcvc2' => '123', ]); }); it('accepts a valid credit card form', function () { $rules = (new UpdateAboCreditCardRequest)->rules(); expect(Validator::make(validCardForm(), $rules)->passes())->toBeTrue(); }); it('rejects invalid credit card input', function (array $override) { $rules = (new UpdateAboCreditCardRequest)->rules(); expect(Validator::make(validCardForm($override), $rules)->fails())->toBeTrue(); })->with([ 'missing holder' => [['cc_cardholder_first' => '']], 'non-numeric pan' => [['cc_cardpan' => '4111-1111-1111']], 'too short pan' => [['cc_cardpan' => '411111']], 'invalid month' => [['cc_cardexpiremonth' => '13']], 'two-digit year' => [['cc_cardexpireyear' => '30']], 'unknown card type' => [['cc_cardtype' => 'X']], 'too short cvc' => [['cc_cardcvc2' => '12']], ]); it('allows updating the card only for active credit-card abos', function () { expect((new UserAbo(['clearingtype' => 'cc', 'status' => 2]))->canUpdatePaymentMethod())->toBeTrue(); expect((new UserAbo(['clearingtype' => 'cc', 'status' => 3]))->canUpdatePaymentMethod())->toBeTrue(); // hold = Kartenwechsel erlaubt }); it('forbids updating the card for non-cc or terminal abos', function (string $clearingtype, int $status) { expect((new UserAbo(['clearingtype' => $clearingtype, 'status' => $status]))->canUpdatePaymentMethod())->toBeFalse(); })->with([ 'paypal (wlt)' => ['wlt', 2], 'cancelled' => ['cc', 4], 'finished' => ['cc', 5], 'inactive' => ['cc', 6], ]);