src/Model/Refund.php
public function sendReceipt($iRefundId, $sEmailOverride = null)
    {
        try {

            $oRefund = $this->getById(
                $iRefundId,
                [
                    'expand' => [
                        ['invoice', ['expand' => ['customer']]],
                        'payment',
                    ],
                ]
            );

            if (empty($oRefund)) {
                throw new PaymentException('Invalid Payment ID', 1);
            }

            if (!in_array($oRefund->status->id, [self::STATUS_PROCESSING, self::STATUS_COMPLETE])) {
                throw new PaymentException('Refund must be in a paid or processing state to send receipt.', 1);
            }

            $oEmail = new \stdClass();

            if ($oRefund->status->id == self::STATUS_COMPLETE) {
                $oEmail->type = 'refund_complete_receipt';
            } else {
                $oEmail->type = 'refund_processing_receipt';
            }

            $oEmail->data = [
                'refund' => $oRefund,
            ];

            if (!empty($sEmailOverride)) {
                //  @todo (Pablo - 2019-01-20) - validate email address (or addresses if an array)
                $aEmails = explode(',', $sEmailOverride);
            } elseif (!empty($oRefund->invoice->customer->billing_email)) {
                $aEmails = explode(',', $oRefund->invoice->customer->billing_email);
            } elseif (!empty($oRefund->invoice->customer->email)) {
                $aEmails = [$oRefund->invoice->customer->email];
            } else {
                throw new PaymentException('No email address to send the receipt to.', 1);
            }

            $aEmails = array_unique($aEmails);
            $aEmails = array_filter($aEmails);

            $oEmailer           = Factory::service('Emailer', 'nails/module-email');
            $oInvoiceEmailModel = Factory::model('InvoiceEmail', 'nails/module-invoice');

            foreach ($aEmails as $sEmail) {

                $oEmail->to_email = $sEmail;
                $oResult          = $oEmailer->send($oEmail);

                if (!empty($oResult)) {
                    $oInvoiceEmailModel->create(
                        [
                            'invoice_id' => $oRefund->invoice->id,
                            'email_id'   => $oResult->id,
                            'email_type' => $oEmail->type,
                            'recipient'  => $oEmail->to_email,
                        ]
                    );
                } else {
                    throw new PaymentException($oEmailer->lastError(), 1);
                }
            }

        } catch (\Exception $e) {
            $this->setError($e->getMessage());
            return false;
        }

        return true;
    }
public function sendReceipt($iRefundId, $sEmailOverride = null)
    {
        try {

            $oRefund = $this->getById(
                $iRefundId,
                [
                    'expand' => [
                        ['invoice', ['expand' => ['customer']]],
                        'payment',
                    ],
                ]
            );

            if (empty($oRefund)) {
                throw new PaymentException('Invalid Payment ID', 1);
            }

            if (!in_array($oRefund->status->id, [self::STATUS_PROCESSING, self::STATUS_COMPLETE])) {
                throw new PaymentException('Refund must be in a paid or processing state to send receipt.', 1);
            }

            $oEmail = new \stdClass();

            if ($oRefund->status->id == self::STATUS_COMPLETE) {
                $oEmail->type = 'refund_complete_receipt';
            } else {
                $oEmail->type = 'refund_processing_receipt';
            }

            $oEmail->data = [
                'refund' => $oRefund,
            ];

            if (!empty($sEmailOverride)) {
                //  @todo (Pablo - 2019-01-20) - validate email address (or addresses if an array)
                $aEmails = explode(',', $sEmailOverride);
            } elseif (!empty($oRefund->invoice->customer->billing_email)) {
                $aEmails = explode(',', $oRefund->invoice->customer->billing_email);
            } elseif (!empty($oRefund->invoice->customer->email)) {
                $aEmails = [$oRefund->invoice->customer->email];
            } else {
                throw new PaymentException('No email address to send the receipt to.', 1);
            }

            $aEmails = array_unique($aEmails);
            $aEmails = array_filter($aEmails);

            $oEmailer           = Factory::service('Emailer', 'nails/module-email');
            $oInvoiceEmailModel = Factory::model('InvoiceEmail', 'nails/module-invoice');

            foreach ($aEmails as $sEmail) {

                $oEmail->to_email = $sEmail;
                $oResult          = $oEmailer->send($oEmail);

                if (!empty($oResult)) {
                    $oInvoiceEmailModel->create(
                        [
                            'invoice_id' => $oRefund->invoice->id,
                            'email_id'   => $oResult->id,
                            'email_type' => $oEmail->type,
                            'recipient'  => $oEmail->to_email,
                        ]
                    );
                } else {
                    throw new PaymentException($oEmailer->lastError(), 1);
                }
            }

        } catch (\Exception $e) {
            $this->setError($e->getMessage());
            return false;
        }

        return true;
    }
public function sendReceipt ( $ iRefundId , $ sEmailOverride = null ) { try { $ oRefund = $ this -> getById ( $ iRefundId , [ 'expand' => [ [ 'invoice' , [ 'expand' => [ 'customer' ] ] ] , 'payment' , ] , ] ) ; if ( empty ( $ oRefund ) ) { throw new PaymentException ( 'Invalid Payment ID' , 1 ) ; } if ( ! in_array ( $ oRefund -> status -> id , [ self :: STATUS_PROCESSING , self :: STATUS_COMPLETE ] ) ) { throw new PaymentException ( 'Refund must be in a paid or processing state to send receipt.' , 1 ) ; } $ oEmail = new \ stdClass ( ) ; if ( $ oRefund -> status -> id == self :: STATUS_COMPLETE ) { $ oEmail -> type = 'refund_complete_receipt' ; } else { $ oEmail -> type = 'refund_processing_receipt' ; } $ oEmail -> data = [ 'refund' => $ oRefund , ] ; if ( ! empty ( $ sEmailOverride ) ) { //  @todo (Pablo - 2019-01-20) - validate email address (or addresses if an array) $ aEmails = explode ( ',' , $ sEmailOverride ) ; } elseif ( ! empty ( $ oRefund -> invoice -> customer -> billing_email ) ) { $ aEmails = explode ( ',' , $ oRefund -> invoice -> customer -> billing_email ) ; } elseif ( ! empty ( $ oRefund -> invoice -> customer -> email ) ) { $ aEmails = [ $ oRefund -> invoice -> customer -> email ] ; } else { throw new PaymentException ( 'No email address to send the receipt to.' , 1 ) ; } $ aEmails = array_unique ( $ aEmails ) ; $ aEmails = array_filter ( $ aEmails ) ; $ oEmailer = Factory :: service ( 'Emailer' , 'nails/module-email' ) ; $ oInvoiceEmailModel = Factory :: model ( 'InvoiceEmail' , 'nails/module-invoice' ) ; foreach ( $ aEmails as $ sEmail ) { $ oEmail -> to_email = $ sEmail ; $ oResult = $ oEmailer -> send ( $ oEmail ) ; if ( ! empty ( $ oResult ) ) { $ oInvoiceEmailModel -> create ( [ 'invoice_id' => $ oRefund -> invoice -> id , 'email_id' => $ oResult -> id , 'email_type' => $ oEmail -> type , 'recipient' => $ oEmail -> to_email , ] ) ; } else { throw new PaymentException ( $ oEmailer -> lastError ( ) , 1 ) ; } } } catch ( \ Exception $ e ) { $ this -> setError ( $ e -> getMessage ( ) ) ; return false ; } return true ; }
Sends refund receipt email

@param  integer $iRefundId      The ID of the refund
@param  string  $sEmailOverride The email address to send the email to

@return bool
Sends refund receipt email