public static function setRefundDispute($class) { if (empty($class)) { throw new Exception("You already refunded for this class", 400); } $trans = self::find()->where(['class_id' => $class->class_id, 'transaction_dispute_status' => 'open'])->all(); if ($trans) { foreach ($trans as $val) { $worldpay = new WorldpayHelper(self::$worldpayKey); // Sometimes your SSL doesnt validate locally // DONT USE IN PRODUCTION $worldpay->disableSSLCheck(true); try { // Refund the order using the Worldpay order code $worldpay->refundOrder($val->transation_id); } catch (Exception $e) { throw new Exception($e->getMessage()); } $transactionData = array("user_id" => $val->user_id, "description" => "Refunded class {$class->class_name}", "transation_id" => $val->transation_id, "status" => 'REFUNDED', "amount" => $val->amount * -1, "currency" => 'USD', "class_id" => $class->class_id, "transaction_refund" => 1); $transactionHistoty = new TransactionHistory(); $transactionHistoty->load($transactionData, ''); if (!$transactionHistoty->save()) { throw new Exception($e->getMessage()); } } } }