直接将信用卡号发送到 Stripe API 通常是不安全的

问题描述 投票:0回答:1

错误说: 发生错误:将信用卡号直接发送到 Stripe API 通常是不安全的。要继续处理,请使用 Stripe.js、Stripe 移动绑定或 Stripe Elements。有关更多信息,请参阅 https://dashboard.stripe.com/account/integration/settings。如果您有资格直接处理卡数据,请参阅https://support.stripe.com/questions/enabling-access-to-raw-card-data-apis。文件:/home/wlms/webapps/wlms-apiv2/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php 行:38

我的后端代码是:

公共函数 doPayment($ paymentRequest) {

    try {

        $payment_transaction_id = $paymentRequest['payment_transaction_id'];

        $zeroDecimalCurrencies = array('BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF');

        if (!in_array($paymentRequest['currency'], $zeroDecimalCurrencies)) {
            $payment_amount = ($paymentRequest['total_value']) * 100;
        } else {
            $payment_amount = $paymentRequest['total_value'];
        }

        $paymentIntentCreate = $this->stripe->paymentIntents->create([
            "amount" => $payment_amount,
            "currency" => $paymentRequest['currency'],
            'payment_method_types' => ['card'],
            'customer' => $paymentRequest['stripe_customer_id']
        ]);

        $paymentIntentConfirm = $this->stripe->paymentIntents->confirm(
            $paymentIntentCreate->id,
            ['payment_method' => $paymentRequest['payment_method_id']]
        );

        $gateWayResponse = PaymentGatewayResponse::create(array('transaction_id' => $payment_transaction_id, 'response' => $paymentIntentConfirm));

        return $paymentIntentConfirm;
    } catch (\Stripe\Exception\CardException $e) {
        ErrorLogger::logError($e);
        return false;
        // Since it's a decline, \Stripe\Exception\CardException will be caught
    } catch (\Stripe\Exception\RateLimitException $e) {
        ErrorLogger::logError($e);
        return false;
        // Too many requests made to the API too quickly
    } catch (\Stripe\Exception\InvalidRequestException $e) {
        ErrorLogger::logError($e);
        return false;
        // Invalid parameters were supplied to Stripe's API
    } catch (\Stripe\Exception\AuthenticationException $e) {
        ErrorLogger::logError($e);
        return false;
        // Authentication with Stripe's API failed
        // (maybe you changed API keys recently)
    } catch (\Stripe\Exception\ApiConnectionException $e) {
        ErrorLogger::logError($e);
        return false;
        // Network communication with Stripe failed
    } catch (\Stripe\Exception\ApiErrorException $e) {
        ErrorLogger::logError($e);
        return false;
        // Display a very generic error to the user, and maybe send
        // yourself an email
    } catch (Exception $e) {
        ErrorLogger::logError($e);
        return false;
        // Something else happened, completely unrelated to Stripe
    }
    $gateWayResponse = PaymentGatewayResponse::create(array('transaction_id' => $payment_transaction_id, 'response' => $e->getMessage()));
    return ['status' => 0, 'data' => $e->getMessage(), 'message' => 'Payment Failed'];
}

聊天 GPT 说前端有错误 确保您的前端正确标记卡数据并仅将标记化的 payment_method_id 发送到后端。

有什么解决办法吗?

php stripe-payments token
1个回答
0
投票

Stripe 提供了卡片形式。 你可以从这里使用它 https://docs.stripe.com/ payments/quickstart

希望这会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.