How to implement 3d secure authentication in stripe?

可紊 提交于 2020-04-17 21:15:17

问题


//Code Sample


<?php
session_start();
require_once("F:\wamp64\www\lib\stripe-php-7.27.2\init.php");
\Stripe\Stripe::setApiKey('sk_test_vXXXXXXXXXXXXXlmwqE');
$name = $_SESSION['namex'];
$email = $_SESSION['emailx'];
$phno = $_SESSION['mobilex'];
$purpose = $_SESSION['purposex'];
$amount = $_SESSION['amountx'];
$txn =   $_SESSION['txnn'];
$token = $_POST['stripeToken'];
$fee  = $amount*0.02;
$tax  = $fee*0.18;
$famt = round($amount+$fee+$tax);
// payment information
$charge = \Stripe\PaymentIntent::create([
  'amount' => $famt*100,
  'currency' => 'inr',
  'receipt_email'=> $email,
]);
$charge -> confirm(['payment_method' => 'pm_card_threeDSecureRequired','return_url' => 'http://localhost/chstripe.php']);
#$charge -> capture();
print_r($charge);
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Payment Status | STRIPE</title>
  </head>
  <body>
    <div class="display-from">
      <table>
<thead> </br> ++++++++++++++++++++++++++++++++++++++++++++++</br>
Final Details Are Given Below </br>++++++++++++++++++++++++++++++++++++++++++++++ </br>
</thead>
<tbody>
  <tr><td>Name:</td><td><?php echo $name; ?></td></tr>
  <tr><td>Email:</td><td><?php echo $email; ?></td></tr>
  <tr><td>Mobile:</td><td><?php echo $phno; ?></td></tr>
  <tr><td>Amount:</td><td><?php echo $amount; ?></td></tr>
  <tr><td>Bank Charge:</td><td><?php echo $fee; ?> </br> <span>(2% of Transaction Amount)</span> </td></tr>
  <tr><td>Tax:</td><td><?php echo $tax; ?> <br><span>(GST 18% Applicable on Bank Charge)</span> </td></tr>
</tbody>
      </table>
    </div>
  </body>
</html>
//Response Log for Stripe Payment Intent




POST /v1/payment_intents/pi_1GPrqLK91kC2EVK/confirm 

200 OK


View log detail


Request parameters
{
  "payment_method": "pm_card_threeDSecureRequired",
  "return_url": "http://localhost/chstripe.php"
}



Response body
{
  "id": "pi_1GPrqLK91kC2EVK",
  "object": "payment_intent",
  "last_payment_error": null,
  "livemode": false,
  "next_action": {
    "redirect_to_url": {
      "return_url": "http://localhost/chstripe.php",
      "url": "https://hooks.stripe.com/redirect/authenticate/src_1GPrqNK91kC2BHdNCUicA4Fq?client_secret=src_client_secret_kFR236NoiN07OUahwN0eR1JB"
    },
    "type": "redirect_to_url"
  },
  "payment_method": "pm_1GPrqMK91kC2BHdNOzYpCnGS",
  "status": "requires_action",
  "amount": 16200,
  "amount_capturable": 0,
  "amount_received": 0,
  "application": null,
  "application_fee_amount": null,
  "canceled_at": null,
  "cancellation_reason": null,
  "capture_method": "automatic",
  "charges": {
    "object": "list",
    "data": [
    ],
    "has_more": false,
    "total_count": 0,
    "url": "/v1/charges?payment_intent=pi_1GPrqLK91kC2EVK"
  },
  "client_secret": "pi_1GPrqVK4Z_secret_GL8c7Y7Wt",
  "confirmation_method": "automatic",
  "created": 1584975933,
  "currency": "inr",
  "customer": null,
  "description": null,
  "invoice": null,
  "metadata": {
  },
  "on_behalf_of": null,
  "payment_method_options": {
    "card": {
      "installments": null,
      "request_three_d_secure": "automatic"
    }
  },
  "payment_method_types": [
    "card"
  ],
  "receipt_email": "Justice.Pouros@yahoo.com",
  "review": null,
  "setup_future_usage": null,
  "shipping": null,
  "source": null,
  "statement_descriptor": null,
  "statement_descriptor_suffix": null,
  "transfer_data": null,
  "transfer_group": null
}

This is the code sample I use to process payment from user. I cannot able to implement 3d secure authentication so my payments are failed showing card doesn't support this type of payment. When I try to contact support they say it's due to lack of 3D secure authentication.Can anyone help me with this. After running this code I check log in stripe dashboard, and it says screenshot >>[ Event Activity/Status ] << and response is given in above snippet.


回答1:


You need to use handleCardAction() [0] on the frontend when you see status: requires_action on a PaymentIntent that you've confirmed on the backend. See Stripe's code example [1] for a basic integration of that step.

[0] https://stripe.com/docs/js/payment_intents/handle_card_action

[1] https://stripe.com/docs/payments/accept-a-payment-synchronously#web-handle-next-actions



来源:https://stackoverflow.com/questions/60817086/how-to-implement-3d-secure-authentication-in-stripe

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