簡體   English   中英

首次成功付款后,條紋計費訂閱不收取“后續費用”

[英]Stripe billing Subscription not charging the “subsequent charges” after initial successful Payment

我已按照文檔實施了“條帶定期付款”,這對於非3d-Secure卡和啟用3d-Secure的卡都可以正常工作。 對於首次付款,我從Stripe獲得了3d-Secure Payment身份驗證模式,以使用3D-Secure Test卡對付款進行身份驗證。

訂閱與Stripe為我生成的發票一起創建。 一切似乎都還可以,但是3D-Secure Enabled(條紋測試卡)的第一次付款成功完成,但是我將間隔設置為1天(用於測試)的后續付款被Stripe“失敗”了。 據我了解,Stripe需要再次進行客戶身份驗證才能繼續訂閱。


他們在

遇到3D Secure時,請配置您的結算設置,以將托管鏈接發送給您的客戶以完成流程。

完全可以,但是,如果第一次付款成功並且開始訂閱,他們為什么還要再次要求身份驗證步驟? 我已經閱讀了所有相關文檔,但沒有發現任何可以防止這種情況的方法。

如果客戶不檢查他/她的電子郵件以返回我的應用程序以驗證付款怎么辦? 要么

代碼有什么問題嗎? 我的意思是,Stripe應該已經保存了付款方式(即卡號),因此每次新的計費周期開始時(每月/每半年),都不需要對后續收費的客戶身份驗證。

我在互聯網上搜索並找到並回答說

您正在使用不支持3ds身份驗證的stripe.createToken。 您需要將客戶端代碼遷移到確實支持它的stripe.createPaymentMethod

是嗎 任何回應表示贊賞

我的Payment.js

// set your stripe publishable key
var stripe = Stripe('pk_test_key');
var elements = stripe.elements();
var style = {
    base: {
        color: '#32325d',
        lineHeight: '18px',
        fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
        fontSmoothing: 'antialiased',
        fontSize: '16px',
        '::placeholder': {
            color: '#aab7c4'
        }
    },
    invalid: {
        color: '#fa755a',
        iconColor: '#fa755a'
    }
};

var cardNumber = elements.create('cardNumber', {
    style: style
});
cardNumber.mount('#cardNumber');
var cardExpiry = elements.create('cardExpiry', {
    style: style
});
cardExpiry.mount('#cardExpiry');
var cardCvc = elements.create('cardCvc', {
    style: style
});
cardCvc.mount('#cardCVC');

var cardholderName = $('#custName').val();
var amount = $('#amount').val();

var cardButton = document.getElementById('makePayment');
cardButton.addEventListener('click', function(ev) {
     // alert();
    ev.preventDefault();




    stripe.createToken(cardNumber).then(function(result) {

    if (result.error) {


    } else {
      //$body.addClass("loading");
      fetch('process.php', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ 
            token_id: result.token.id          
            })
      }).then(function(result) {


        // Handle server response (see Step 3)
        result.json().then(function(json) {
          handleServerResponse(json);
          //alert();
        })
      });
    }
  });
});
function handleServerResponse(response) {
            if (response.error) {
                // Show error from server on payment form
            } else if (response.requires_action) {
                // Use Stripe.js to handle required card action
                var action = response.next_action;
                if (action && action.type == 'redirect_to_url') {
                    window.location = action.redirect_to_url.url;
                }

                handleAction(response);

            } else {
                console.log("3D" + response);
            }
}

        function handleAction(response) {
           var paymentIntentSecret = response.payment_intent_client_secret;
            stripe.handleCardPayment(paymentIntentSecret).then(function(result) {
              if (result.error) {
                // Display error.message in your UI.
              } else {
                // The payment has succeeded. Display a success message.
                alert('Payment succeeded!');
              }
});

}

Process.php

<?php 

require_once('stripe-php/init.php');   
\Stripe\Stripe::setApiKey('sk_test_key');

$json_str = file_get_contents('php://input');

$json_obj = json_decode($json_str);
 //print_r($json_obj->token_id);die;

  //$intent = null;
try {
    if (isset($json_obj->token_id)) {
     //Create Customer   
    $customer = \Stripe\Customer::create([
    "email" => "test@gmail.com",
    "name" => "Haroon",  
    "source" => $json_obj->token_id,
]);
    //create product
    $product = \Stripe\Product::create([
    'name' => 'Water',
    'type' => 'service',
]);
    //create a plan
    $plan = \Stripe\Plan::create([
      'product' => $product->id,
      'nickname' => 'Water',
      'interval' => 'day',
      'currency' => 'eur',
      'amount' => 1200.00,
    ]);   

    //add subscription to stripe
    $subscription = \Stripe\Subscription::create([

        'customer' => $customer->id,
        'items' => [[
        "plan" => $plan->id],],
        'expand' => ['latest_invoice.payment_intent'],
]);    
}

      $intent = \Stripe\PaymentIntent::retrieve($subscription->latest_invoice->payment_intent->id);

      $subscription = \Stripe\Subscription::retrieve($subscription->id);
    //   $intent->confirm();
    // }
    generatePaymentResponse($intent,$subscription);
  }catch (\Stripe\Error\Base $e) {
    # Display error on client
    echo json_encode([
      'error' => $e->getMessage()
    ]);
  }  

   function generatePaymentResponse($intent,$subscription) {
    if ($intent->status == 'requires_action' && $subscription->status == 'incomplete' &&
        $intent->next_action->type == 'use_stripe_sdk' ) {
        # Tell the client to handle the action

        echo json_encode([
            'requires_action' => true,
            'payment_intent_client_secret' => $intent->client_secret
        ]);
    } else if ($intent->status == 'succeeded' && $subscription->status == 'active') {

        # The payment didn’t need any additional actions and completed!
        # Handle post-payment fulfillment
        echo json_encode([
            'success' => true
        ]);
    } else if ($intent->status == 'requires_payment_method' && $subscription->status == 'incomplete') {
        echo "Subscription failed";

    } else {
        # Invalid status
        http_response_code(500);
        echo json_encode(['error' => 'Invalid PaymentIntent status']);
    }
}

如果您正在為已經存在的卡執行此操作,那么我將在一天前完成此操作。 請參閱此文檔https://stripe.com/docs/payments/3d-secure

這表明您需要創建paymentIntent並需要確認此付款意圖。 在3ds中也有測試卡4242 4242 42424242。該卡不需要3ds的任何身份驗證。 在下面提供測試卡的鏈接

https://stripe.com/docs/payments/3d-secure/web#three-ds-cards

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM