drupal has a module called uc_paypal.module which has this part of the code.
// 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);
}
What I would like to do is create a link button that can refund a completed order.
I found this API code example.
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"
}
}
]
}
}'
What I would like to do is load the data from the database using this code to get the TxnId for the order.
$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);
And join all three items into one PHP call to Paypal to refund the order. I just don't know how to join those codes together.
CodePudding user response:
That code example is for the current REST API, which uses a clientid and secret for authentication to first obtain an access token.
The uc_paypal.module uses the much older (15 years) classic NVP API, which authenticates with a USER, PWD, SIGNATURE.
It's generally not a good idea to mix very old and current APIs. Here's the API reference for a classic API RefundTransaction call.