/**
  *
  * @param \GridField $gridField
  * @param \DataObject $record
  * @param string $columnName
  * @return string|null - the HTML for the column
  */
 public function getColumnContent($gridField, $record, $columnName)
 {
     if (!$record instanceof \Payment) {
         return null;
     }
     if (!$record->canRefund()) {
         return null;
     }
     \Requirements::css('omnipay-ui/css/omnipay-ui-cms.css');
     \Requirements::javascript('omnipay-ui/javascript/omnipay-ui-cms.js');
     \Requirements::add_i18n_javascript('omnipay-ui/javascript/lang');
     $infoText = '';
     switch (GatewayInfo::refundMode($record->Gateway)) {
         case GatewayInfo::MULTIPLE:
             $infoText = 'MultiRefundInfo';
             break;
         case GatewayInfo::PARTIAL:
             $infoText = 'SingleRefundInfo';
             break;
         case GatewayInfo::FULL:
             $infoText = 'FullRefundInfo';
             break;
     }
     /** @var \Money $money */
     $money = $record->dbObject('Money');
     /** @var \GridField_FormAction $field */
     $field = \GridField_FormAction::create($gridField, 'RefundPayment' . $record->ID, false, 'refundpayment', array('RecordID' => $record->ID))->addExtraClass('gridfield-button-refund payment-dialog-button')->setAttribute('title', _t('GridFieldRefundAction.Title', 'Refund Payment'))->setAttribute('data-icon', 'button-refund')->setAttribute('data-dialog', json_encode(array('maxAmount' => $money->Nice(), 'maxAmountNum' => $money->getAmount(), 'hasAmountField' => $record->canRefund(null, true), 'infoTextKey' => $infoText, 'buttonTextKey' => 'RefundAmount')))->setDescription(_t('GridFieldRefundAction.Description', 'Refund a captured payment'));
     return $field->Field();
 }
Ejemplo n.º 2
0
 /**
  * Whether or not this payment can be refunded
  * @param Member|int $member the member/memberID to check permissions on
  * @param boolean $partial check if payment can be partially refunded. Defaults to false
  * @return bool
  */
 public function canRefund($member = null, $partial = false)
 {
     if (!($this->Status == 'Captured' && ($partial ? GatewayInfo::allowPartialRefund($this->Gateway) : GatewayInfo::allowRefund($this->Gateway)))) {
         return false;
     }
     if ($this->isInDB()) {
         // Check if there are partial refunds and deny further refunds if multiple refunds aren't enabled
         $hasPartials = $this->getPartialPayments()->filter('Status', array('Refunded', 'PendingRefund'))->count() > 0;
         if ($hasPartials && GatewayInfo::refundMode($this->Gateway) !== GatewayInfo::MULTIPLE) {
             return false;
         }
     }
     $extended = $this->extendedCan('canRefund', $member);
     if ($extended !== null) {
         return $extended;
     }
     return Permission::check('REFUND_PAYMENTS', 'any', $member);
 }