I am trying to implement a subscription with Cashier. I am not using the user table but a customer table which I have defined OK in .env with
CASHIER_MODEL=App\Customer
The appropriate other fields are added to the customer table.
I first wish to get some information on the customer so they fill in a simple form which includes their name, email, country and a password. I then save the customer->id as a session variable.
I have a table of plans which contains the stripe subscription reference and the test reference. I have set these up in Stripe.
After recording the customer details I take them to a view which is where they input their card details. The customer is found on this page as the id is passed to the view and also set a session variable.
$fs = App\Customer::find($id);
$pl = App\Plan::find(3);
$amount = $pl->cost * 100;
session(['subscriber' => $id]);
Plan id 3 is my test plan but will be replaces when I get things to work and so my form is
<form action="/subscriptionPayment" method="POST">
@csrf
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key=""
data-amount=""
data-name=""
data-email=""
data-currency="gbp">
</script>
</form>
This does record the stripeID in the table but not the last 4 numbers of the card or the card brand. (I am using 4242 4242 4242 4242).
The controller method is
public function subscriptionPayment(Request $request)
{
$pl = Plan::find(3);
$amount = $pl->cost *100;
$cu = Cust::find( session('customer') );
$paymentMethods = $cu->paymentMethods();
$intent = $cu->createSetupIntent();
$stripeToken = $cu->stripe_id;
$cu->newSubscription($pl->name, $pl->test_stripe_plan)->create($stripeToken); //test strip id
return 'Charge successful, you get the course!';
}
}
I did dd the $intent which returned
Stripe\SetupIntent {#500 ▼
+saveWithParent: false
#_opts: Stripe\Util\RequestOptions {#503 ▶}
#_originalValues: array:20 [▶]
#_values: array:20 [▶]
#_unsavedValues: Stripe\Util\Set {#490 ▶}
#_transientValues: Stripe\Util\Set {#506 ▶}
#_retrieveOptions: []
#_lastResponse: Stripe\ApiResponse {#502 ▶}
id: "seti_1FyFFyF7aDMrgjaujaPqH939"
object: "setup_intent"
application: null
cancellation_reason: null
client_secret: "seti_1FyFFyF7aDMrgjaujaPqH939_secret_GVFlyidVC9hiJVM3FDrXMoyxO0etcPL"
created: 1578392750
customer: null
description: null
last_setup_error: null
livemode: false
mandate: null
metadata: Stripe\StripeObject {#512 ▶}
next_action: null
on_behalf_of: null
payment_method: null
payment_method_options: Stripe\StripeObject {#508 ▶}
payment_method_types: array:1 [▶]
single_use_mandate: null
status: "requires_payment_method"
usage: "off_session"
}
The subscription fails with
No such PaymentMethod: cus_GVEuKhg2BUE7BB
This is the correct customer number as recorded in the database.
Help greatly appreciated indeed.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire