我已经将stripe PHP集成到woocommerce中,但当试图处理付款时,我得到了这个错误
没有这样的付款方式:自定义
下面是代码
<?php
/**
* Plugin Name: Stripe-PHP-integration
* Description: PHP API Integration For Wordpress
* Author: Null
* Version: 1.0
**/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
require_once 'stripe/init.php';
use Stripe\Stripe;
add_action('init', function() {
Stripe::setApiKey('sk_test_....');
Stripe::setClientId('pk_test_....');
});
add_action('plugins_loaded', 'init_custom_gateway_class');
function init_custom_gateway_class(){
class WC_Gateway_Custom extends WC_Payment_Gateway {
/**
* Constructor for the gateway.
*/
public function __construct() {
$this->id = 'custom';
$this->icon = apply_filters('woocommerce_custom_gateway_icon', '');
$this->has_fields = false;
$this->method_title = __( 'Stripe PHP API Integration For WooCommerce', $this->domain );
$this->method_description = __( 'Allows payments using Stripe PHP API', $this->domain );
// Load the settings.
$this->init_form_fields();
$this->init_settings();
// Define user set variables
$this->title = $this->get_option( 'title' );
$this->description = $this->get_option( 'description' );
$this->instructions = $this->get_option( 'instructions', $this->description );
$this->order_status = $this->get_option( 'order_status', 'pending' );
// Actions
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
add_action( 'woocommerce_thankyou_' . $this->id, array( $this, 'thankyou_page' ) );
// Customer Emails
add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 );
add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
}
字符串
它与这一部分有关,具体来说就是$this->id = 'custom';
因为当我删除它时,我得到错误-您为'payment_method'传递了一个空字符串。我们假设空值是试图取消设置参数;但是'payment_method'无法取消设置。您应该从请求中删除'payment_method'或提供非空值。
当我检查条带日志时,我可以看到正在进行请求,但付款对象有问题。
下面是process_order函数
public function process_payment( $order_id ) {
$order = wc_get_order( $order_id );
$status = 'wc-' === substr( $this->order_status, 0, 3 ) ? substr( $this->order_status, 3 ) : $this->order_status;
$payment_intent = \Stripe\PaymentIntent::create(array(
'amount' => $order->get_total() * 100,
'currency' => strtolower( get_woocommerce_currency() ),
'payment_method' => $order->get_payment_method(),
'confirmation_method' => 'manual',
'confirm' => true,
));
// Set order status
$order->update_status( $status, __( 'Checkout with custom payment. ', $this->domain ) );
// or call the Payment complete
// $order->payment_complete();
// Remove cart
WC()->cart->empty_cart();
// Return thankyou redirect
return array(
'result' => 'success',
'redirect' => $this->get_return_url( $order )
);
}
型
1条答案
按热度按时间sg24os4d1#
你错过了注册支付网关与WooCommerce挂钩。
添加下面的代码片段,然后您的问题将得到解决。
字符串
删除/注解此行后尝试
型