Skip to content
Snippets Groups Projects
Commit 0f103473 authored by mattwire's avatar mattwire
Browse files

Add basic support for PaymentProcessor.refund API

parent a0cab58e
Branches
Tags
No related merge requests found
......@@ -141,6 +141,15 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
return FALSE;
}
/**
* Does this payment processor support refund?
*
* @return bool
*/
public function supportsRefund() {
return TRUE;
}
/**
* We can configure a start date for a smartdebit mandate
* @return bool
......@@ -558,6 +567,38 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
return $params;
}
/**
* Submit a refund payment
*
* @param array $params
* Assoc array of input parameters for this transaction.
*
* @throws \Civi\Payment\Exception\PaymentProcessorException
*/
public function doRefund(&$params) {
$requiredParams = ['charge_id', 'payment_processor_id'];
foreach ($requiredParams as $required) {
if (!isset($params[$required])) {
$message = 'Stripe doRefund: Missing mandatory parameter: ' . $required;
Civi::log()->error($message);
Throw new \Civi\Payment\Exception\PaymentProcessorException($message);
}
}
$refundParams = [
'charge' => $params['charge_id'],
];
if (!empty($params['amount'])) {
$refundParams['amount'] = $this->getAmount($params);
}
try {
$refund = \Stripe\Refund::create($refundParams);
}
catch (Exception $e) {
$this->handleError($e->getCode(), $e->getMessage());
Throw new \Civi\Payment\Exception\PaymentProcessorException($e->getMessage());
}
}
/**
* Calculate the end_date for a recurring contribution based on the number of installments
* @param $params
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment