Storing Stripe Recurring Payment information in Database

∥☆過路亽.° 提交于 2019-12-22 23:20:42

问题


I am new to stripe payment gateway and I have created a stripe account where I have my plans and subscriptions. It is working fine. Below are my plans and subscriptions in image format.

My Stripe subscription plan

My Stripe Subscriptions

Below is my checkout page

<form action="charge.php" method="POST">
<script
    src="https://checkout.stripe.com/checkout.js" class="stripe-button"
    data-key="pk_test_ZCRfEl8XeRIbPHGIifY3THYC"
    data-amount="999"
    data-name="Demo Site"
    data-description="Widget"
    data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
    data-locale="auto">
</script>

I want to insert customer info like amount of transaction, customer id etc.., into my database when recurring payment occurs in stripe method. Can anyone help me?


回答1:


You have to use webhook to get the data when recurring payment happen.

  1. Create an endpoint in your application to parse the webhook data and store as you want
  2. Add the created endpoint to your stripe dashboard's webhook to indicate Stripe to request on the endpoint.



回答2:


You can do with $customer varibale after successful Payment .you can Collect whole information about payment by $customer If you want to access the collecting card and recurring information after successful payment, you'd need to do

$StripeId = $customer['id'];    
$card = $customer->sources->data[0];
$Stripe_City = $card->address_city;
$Stripe_Country = $card->address_country;
$Stripe_Address = $card->address_line1;
$Stripe_State = $card->address_state;
$Stripe_Zip = $card->address_zip;
$Stripe_card = $card->last4;
$Stripe_Brand = $card->brand;

for storing information about customer you need to add this on process:

$customer = Stripe_Customer::create(array(
'email' => $_SESSION['userEmail'],
'card' => $_POST['stripeToken'],
'plan' => $plan_id,
 ));`

stripe also provide you information about payment, see all object by print_r($customer).A $customer can have more than one source at the same time. The source property on the Customer is a list as documented here.



来源:https://stackoverflow.com/questions/47178783/storing-stripe-recurring-payment-information-in-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!