drupal有一个名为uc_paypal.module的模块,它包含代码的这一部分。
// Sends a request to PayPal and returns a response array.
function uc_paypal_api_request($request, $server) {
$request['USER'] = variable_get('uc_paypal_api_username', '');
$request['PWD'] = variable_get('uc_paypal_api_password', '');
$request['VERSION'] = '3.0';
$request['SIGNATURE'] = variable_get('uc_paypal_api_signature', '');
$data = '';
foreach ($request as $key => $value) {
$data .= $key .'='. urlencode(ereg_replace(',', '', $value)) .'&';
}
$data = substr($data, 0, -1);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $server);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_NOPROGRESS, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,0);
$response = curl_exec($ch);
if ($error = curl_error($ch)) {
watchdog('uc_paypal', $error, WATCHDOG_ERROR);
}
curl_close($ch);
return _uc_paypal_nvp_to_array($response);
}
我想做的是创建一个链接按钮,可以退款一个完整的订单。
我找到了这个API代码示例。
curl -v -X POST https://api-m.sandbox.paypal.com/v2/payments/captures/2GG279541U471931P/refund \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <Access-Token>" \
-H "PayPal-Request-Id: 123e4567-e89b-12d3-a456-426655440020" \
-d '{
"amount": {
"value": "10.00",
"currency_code": "USD"
},
"invoice_id": "INVOICE-123",
"note_to_payer": "DefectiveProduct",
"payment_instruction": {
"platform_fees": [
{
"amount": {
"currency_code": "USD",
"value": "1.00"
}
}
]
}
}'
我想要做的是使用下面的代码从数据库中加载数据,以获得订单的TxnId。
$result = db_query("SELECT order_id, txn_id
FROM uc_payment_paypal_ipn WHERE status = 'Completed' AND uid = %d AND order_id = %d", $uid, $order->order_id);
并加入所有三个项目到一个PHP调用Paypal,以退款的订单。我只是不知道怎么把这些密码连在一起。
发布于 2022-12-03 20:01:29
该代码示例用于当前REST,它使用客户端和机密进行身份验证,以首先获得访问令牌。
uc_paypal.module使用更老的(15+年份)经典的NVP,它使用用户PWD签名进行身份验证。
通常,将非常老的API和当前的API混合使用并不是一个好主意。下面是API引用用于典型的API RefundTransaction调用。
https://stackoverflow.com/questions/74670206
复制相似问题