Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

gazd1977's avatar

CVC checks on createPaymentMethod - Stripe

I'm trying to work through the subscriptions guide on stripe

Im using seperate elements for Cardnumber, Expiry and CVC (as below)

<div id="card-number" class="MyCardNumber">
    <!-- Elements will create input elements here -->
</div>
<div id="card-expiry" class="MyCardExpiry">
    <!-- Elements will create input elements here -->
</div>
<div id="card-cvc" class="MyCardCvc">
    <!-- Elements will create input elements here -->
</div>

Everything is rendering on screen correctly and when i submit (using the createPaymentMethod as detailed here) i am getting a payment method object returned (so its working) - example below.

paymentMethod:
billing_details:
address:
city: "somwhere"
country: "US"
line1: "123 fake street"
line2: "fake something"
postal_code: "12345"
state: "new york"
__proto__: Object
email: "[email protected]"
name: "john doe"
phone: null
__proto__: Object
card:
brand: "visa"
checks:
address_line1_check: null
address_postal_code_check: null
cvc_check: null
__proto__: Object
country: "US"
exp_month: 2
exp_year: 2020
funding: "credit"
generated_from: null
last4: "4242"
three_d_secure_usage: {supported: true}
wallet: null
__proto__: Object
created: 1575838186
customer: null
id: "pm_1FnWhKDEOzF6SOM2om8fNlSi"
livemode: false
metadata: {}
object: "payment_method"
type: "card"
__proto__: Object
__proto__: Object

What i am struggling to understand/work out is how to make the createPaymentMethod perform checks on the postal_code and CVC (the checks are returning as null).

Are the checks only performed when using the single card element or can they be performed when collecting cardnumber/expiry and CVC seperately? I read a post on stack overflow which suggests stripe.js magically does this under the hood, but i dont cant work out what im missing?

Thanks

0 likes
3 replies
gazd1977's avatar

Just in case any else stumbles across this......

It would appear (after talking to stripe on irc) that these 'checks' are not performed during the initial submission of card details. Stripe does perform some sense checks on the card number and expiry date, but the below are validated only at the point of trying to complete the payment

checks:
address_line1_check: null
address_postal_code_check: null
cvc_check: null
gazd1977's avatar

Sure (im following this, so my controller is basically as the stripe example.

namespace App\Http\Controllers;

use Stripe\Stripe;
use Stripe\Customer;
use Illuminate\Http\Request;

class StripeCreateCustomerController extends Controller
{
    public function handle(Request $request)
    {
        $string = json_decode($request->data);

        Stripe::setApiKey(config('services.stripe.secret'));

        $customer = Customer::create([
        "payment_method" => $string->payment_method,
        "email" => $string->email,
        "invoice_settings" => [
            "default_payment_method" => $string->payment_method
        ]
        ]);

        return $customer;
    }
}

Im still working through that example of setting up a subscription so this may develop over time.

Please or to participate in this conversation.