我需要在Woocommerce payfast插件中添加“内容”,以使其能够处理拆分付款,根据Payfast网站,它看起来像这样:
{ "split_payment" : { "merchant_id":10000105, "percentage":10, "amount":500, "min":100, "max":100000 } }
,它是通过以下形式提交的:
<input type="hidden" name="setup" value='{ "split_payment" : {
"merchant_id":10000105,
"percentage":10,
"min":100,
"max":100000}}' >
我已经查看了class-wc-gateway-payfast.php
文件,但是看不到可以在哪里“注入”文件,并且我已经找到了html表单,也没有找到任何一个....我的直觉告诉我,这很简单,但是我无法绕开它:
可以在此处找到给我说明的Payfast链接(以防我无法正确阅读):https://developers.payfast.co.za/documentation/?html#direct-request-method
我是否认为它必须在这里不正确?
/**
* Generate the PayFast button link.
*
* @since 1.0.0
*/
public function generate_payfast_form( $order_id ) {
$order = wc_get_order( $order_id );
// Construct variables for post
$this->data_to_send = array(
// Merchant details
'merchant_id' => $this->merchant_id,
'merchant_key' => $this->merchant_key,
'return_url' => $this->get_return_url( $order ),
'cancel_url' => $order->get_cancel_order_url(),
'notify_url' => $this->response_url,
// Billing details
'name_first' => self::get_order_prop( $order, 'billing_first_name' ),
'name_last' => self::get_order_prop( $order, 'billing_last_name' ),
'email_address' => self::get_order_prop( $order, 'billing_email' ),
// Item details
'm_payment_id' => ltrim( $order->get_order_number(), _x( '#', 'hash before order number', 'woocommerce-gateway-payfast' ) ),
'amount' => $order->get_total(),
'item_name' => get_bloginfo( 'name' ) . ' - ' . $order->get_order_number(),
/* translators: 1: blog info name */
'item_description' => sprintf( __( 'New order from %s', 'woocommerce-gateway-payfast' ), get_bloginfo( 'name' ) ),
// Custom strings
'custom_str1' => self::get_order_prop( $order, 'order_key' ),
'custom_str2' => 'WooCommerce/' . WC_VERSION . '; ' . get_site_url(),
'custom_str3' => self::get_order_prop( $order, 'id' ),
'source' => 'WooCommerce-Free-Plugin',
);
答案 0 :(得分:1)
根据关联数组生成表单。您必须将以下内容添加到数组中以进行拆分付款:
@staticmethod
'setup' => json_encode(['split_payment' => ['merchant_id' => 10000105, 'percentage'=>10, 'min' => 100, 'max' => 100000]]),
函数用于将PHP多维数组转换为JSON对象。可以在here上找到有关json_encode()
函数的更多信息。
完整的数组如下:
json_encode()