This paper briefly introduces the processing of wechat refund request and some matters needing attention
Series of articles
Series 1 wechat App payment full resolution series 2 Alipay App Payment full resolution series 3 wechat public account payment full resolution series 4 wechat scan code payment full resolution series 5 Alipay instant payment full resolution series 6 wechat refund full resolution series 7 Alipay refund full resolution series 8 Full analysis of alipay open platform payment updates and upgrades
1 Applying for a Refund
Official Interface documentation
If the buyer or seller needs a refund within a period of time after the transaction occurs, the seller can refund the payment to the buyer through the refund interface. Wechat Pay will refund the payment to the buyer’s account according to the original way after receiving the refund request and verifying the success.
Note:
- Orders that have been traded for more than a year cannot be submitted for a refund
- Wechat Pay refund supports multiple refunds for a single transaction. For multiple refunds, the merchant order number of the original payment order should be submitted and different refund tracking number should be set. If a refund fails to be resubmitted, the original refund tracking number should be used. The total amount of refund cannot exceed the amount actually paid by the user.
Certificate verification is required. Certificate download: for refund and other need certificate authentication interface use. Click “Account Center – API Security” on wechat merchant platform and click “Download certificate”
Pem, apiclient_key.pem, and rootca.pem certificates are displayed when you open the compressed file package.
$appid = ""; Your appid / /
$mch_id = ""; / / merchant id
$wx_api_key = ""; // Merchant API key
$out_trade_no = ""; // The transaction number of the transaction to be refunded
$out_refund_no = ""; // The unique refund receipt number generated by the business
$total_fee = "1"; // Total amount of transactions to be refunded
$refund_fee = "1"; // The refund amount is in minutes
$REFUND_URL = "https://api.mch.weixin.qq.com/secapi/pay/refund"; / / refund
$data = array(a); $data['appid'] = $appid;
$data['mch_id'] =$mch_id;
$data['nonce_str'] = randomStr(20); // A random 20-character string
$data['out_trade_no'] = $out_trade_no;
$data['out_refund_no'] = $out_refund_no;
$data['total_fee'] = $total_fee;
$data['refund_fee'] = $refund_fee;
$data['op_user_id'] = mch_id;
$data['sign'] =sign($data, $wx_api_key); / / signature
// Convert to XML format
$xml_str = arrayToXmlStr($data);
// Certificate Settings
$opt_arr = array(
CURLOPT_SSLCERT => ".. /" . $config['wx_pemcert'],
CURLOPT_SSLKEY => ".. /" . $config['wx_pemkey'],
CURLOPT_CAINFO => ".. /key/wx_rootca.pem");
// Send the request using the wrapped curl_POST
$result = Curl::curl_post($REFUND_URL, $xml_str, $opt_arr);
// Parse the resulting value
$get_data = simplexml_load_string($raw_data, 'SimpleXMLElement', LIBXML_NOCDATA);
$get_para = array(a); $get_sign ="";
foreach ($get_data->children() as $child)
{
if($child->getName() == 'sign') {
$get_sign = strval($child);
} else{ $get_para[strval($child->getName())] = strval($child); }}if($get_para['return_code']! = ="SUCCESS") {
//return code fail
}
// Verify the signature
if(! verifySign($get_sign, $get_para, $wx_api_key)) {// Verify that the signature is invalid
}
// Verify the result code
if($get_para['result_code']! = ='SUCCESS') {
// Application failed
}
// Successful application for refund
//todoCopy the code
2 Refund Enquiry
Since wechat refund will arrive at different times according to the payment channel, all wechat does not provide the receipt callback itself. Successful refund application does not mean successful receipt of the account. All business parties need to check the refund status periodically. Generally, the change and bank card payment will arrive in 20 minutes, and the credit card will arrive in 2-3 days.
Therefore, I set the scheduled task to query the refund in 15s, 2min, 20min, 1day, 1day, 2day, 2day.
Official Interface documentation
$appid = ""; Your appid / /
$mch_id = ""; / / merchant id
$wx_api_key = ""; // Merchant API key
$out_refund_no = ""; // The number of the refund receipt to be queried
$REFUND_QUERY_URL = "https://api.mch.weixin.qq.com/pay/refundquery"; // Refund enquiry
$data = array(a); $data['appid'] = $appid;
$data['mch_id'] =$mch_id;
$data['nonce_str'] = randomStr(20); // A random 20-character string
$data['out_refund_no'] = $out_refund_no;
$data['sign'] =sign($data, $wx_api_key); / / signature
// Convert to XML format
$xml_str = arrayToXmlStr($data);
// Send the request using the wrapped curl_POST
$result = Curl::curl_post($REFUND_QUERY_URL, $xml_str);
// Parse the resulting value
$get_data = simplexml_load_string($raw_data, 'SimpleXMLElement', LIBXML_NOCDATA);
$get_para = array(a); $get_sign ="";
foreach ($get_data->children() as $child)
{
if($child->getName() == 'sign') {
$get_sign = strval($child);
} else{ $get_para[strval($child->getName())] = strval($child); }}if($get_para['return_code']! = ="SUCCESS") {
//return code fail
}
// Verify the signature
if(! verifySign($get_sign, $get_para, $wx_api_key)) {// Verify that the signature is invalid
}
// Verify the result code
if($get_para['result_code']! = ='SUCCESS') {
// Record the refund failure log
//todo
}
// Refund The refund status is successfully modified
//todoCopy the code
At the end
More articles follow my public account