ReactJS中的PayFast付款集成

时间:2019-11-30 09:55:21

标签: javascript node.js reactjs

我正在尝试将PayFast付款集成到ReactJS中。

根据PayFast的the documentation,当表单作为POST请求提交时,用户将被定向到PayFast付款页面。

我如何知道何时从notify_url完成付款或取消付款?

PayFast仅显示PHP示例。我还可以通过NodeJS处理吗?

1 个答案:

答案 0 :(得分:0)

我已经在ReactJS中成功实现了它,希望对您有所帮助。 我在前端所做的事情使所需信息成为对象。

const params = new URLSearchParams({
  merchant_id: "....",
  merchant_key: "....",
  return_url: "https://yourApplication/paymentscreen",
  cancel_url: "https://yourApplication/paymentscreen",
  notify_url: "https://yourApplication/paymentscreen",
  name_first: name,
  email_address: email,
  m_payment_id: unique_id_for_user,
  amount: amount,
  item_name: payment_name,
  item_description: description_if_any,
  custom_int1: custome_integer_value_if_any,
  custom_str1: custome_string_value_if_any,
  custom_str2: custome_string_value_if_any,
  passphrase: passphrase_set_in_payfast_account.
});

// Create an MD5 signature of it.
const MD5Signature = md5(params.toString())

现在,在点击付款按钮后,我确实提交了一个隐藏表格。 确保顺序很重要,在这里他们确实提到了有关字段顺序的任何信息,但我也面临许多问题,但经过过多的调试后,我得到了正确的顺序。

<form action="https://www.payfast.co.za/eng/process" method="POST">
          <input type="hidden" name="merchant_id" value="...." />
          <input type="hidden" name="merchant_key" value="....." />
          <input type="hidden" name="return_url" value="https://yourApplication/paymentscreen" />
          <input type="hidden" name="cancel_url" value="https://yourApplication/paymentscreen" />
          <input type="hidden" name="notify_url" value="https://yourApplication/paymentscreen" />
          <input type="hidden" name="name_first" value={name} />
          <input type="hidden" name="email_address" value={email} />
          <input type="hidden" name="m_payment_id" value={unique_id_for_user} />
          <input type="hidden" name="amount" value={amount} />
          <input type="hidden" name="item_name" value={payment_name} />
          <input type="hidden" name="item_description" value={description_if_any} />
          <input type="hidden" name="custom_int1" value={custome_integer_value_if_any} />
          <input type="hidden" name="custom_str1" value={custome_string_value_if_any} />
          <input type="hidden" name="custom_str2" value={custome_string_value_if_any} />
          <input type="hidden" name="passphrase" value="passphrase" />
          <input type="hidden" name="signature" value={MD5Signature} />
          <div className="row" style={{display: 'flex', justifyContent: 'center', alignItems: 'center'}}>
            <div className="col-lg-6">
              <img alt="payfast" src="../public/upload/payfastpaynow.png" vspace="3" width="100%" height="100%" />
            </div>
            <div className="col-lg-6">
                <input style={{marginRight: 20, float: 'right'}} name="disable" type="submit" disabled={isEnablePayment} width="100%" height="100%" alt="Submit" align="bottom" value="Purchase" />
            </div>
          </div>
        </form>