Reverse a previous payment

@param OneClickReverseInput $codeReverseOneClickInput Reverse information
@return mixed
@throws \Freshwork\Transbank\Exceptions\InvalidCertificateException
@throws \SoapFault
976557
public function codeReverseOneClick(OneClickReverseInput $codeReverseOneClickInput)
    {
        $codeReverseOneClick = new CodeReverseOneClick();
        $codeReverseOneClick->arg0 = $codeReverseOneClickInput;

        return $this->callSoapMethod('codeReverseOneClick', $codeReverseOneClick);
    }
1122513
public function reverse() {
		if(!$this->orderBy)
			throw new \Exception('Cannot reverse a query without order by.');

		preg_match_all('/([^,])*([(].*?[)])([^,])*|([^,])+/', $this->orderBy, $e);
		$e = $e[0];
		foreach($e as $k=>$v) {
			$v = preg_replace_callback('/(DESC|ASC)[\s]*/', function($r) {
				$r = $r[0];
				if(strpos($r, 'DESC') !== false)
					return str_replace('DESC', 'ASC', $r);
				else
					return str_replace('ASC', 'DESC', $r);
			}, $v, -1, $c);
			if($c === 0)
				$v = $v.' DESC';
			$e[$k] = $v;
		}
		$orderBy = implode(', ', $e);

		$this->orderBy($orderBy);
		return $this;
	}
60378
public function recurrentPayment($authorizeNow = true)
    {
        $recurrentPayment = new RecurrentPayment($authorizeNow);

        $this->setRecurrentPayment($recurrentPayment);

        return $recurrentPayment;
    }
522061
public static function reverseOrder($order)
	{
		if (!trim($order))
			return $order;

		$parts = explode(',',$order);

		for ($i=0,$n=count($parts); $i<$n; ++$i)
		{
			$v = strtolower($parts[$i]);

			if (strpos($v,' asc') !== false)
				$parts[$i] = preg_replace('/asc/i','DESC',$parts[$i]);
			elseif (strpos($v,' desc') !== false)
				$parts[$i] = preg_replace('/desc/i','ASC',$parts[$i]);
			else
				$parts[$i] .= ' DESC';
		}
		return join(',',$parts);
	}
564896
public function reverse()
	{
		$length = $this->length();
		$reversed = '';
		while ($length-- > 0) {
			$reversed .= mb_substr($this->string, $length, 1, mb_detect_encoding($this->string));
		}
		$this->string = $reversed;
		return $this;
	}
989014
public function reverse()
	{
		$oldString		= $this->string;
		$this->string	= strrev( $this->string );
		return $this->string !== $oldString;
	}
527281
public function reverse() : self
    {
        $list = $this->list;
        $count = $this->list->getSize();
        $newList = new \SplFixedArray($count);

        foreach ($newList as $index => $val) {
            $newList[$index] = $list[$count - $index - 1];
        }

        return new static($newList);
    }
334138
public function reverse()
    {
        $entities = new Entities();

        foreach (array_reverse($this->_entities) as $entity) {
            $entities->add($entity);
        }

        return $entities;
    }
834332
def reverseCommit(self):
        
        if self.selectionPosOld is None:
            return

        # Shorthand.
        wid = self.qteWidget

        # Select, backup, and delete the selection.
        wid.setSelection(*self.selectionPosNew)
        self.baseClass.replaceSelectedText(self.oldText)

        # Add the styling information.
        line, col = self.selectionPosNew[0:2]
        wid.SCISetStylingEx(line, col, self.oldStyle)
        wid.setCursorPosition(line, col)
681984
public function reverseTransform($flags)
    {
        if (null === $flags) {
            return null;
        }

        if (!\is_array($flags)) {
            throw new TransformationFailedException(sprintf(
                'Expected array. Got "%s".',
                \is_object($flags) ? \get_class($flags) : \gettype($flags)
            ));
        }

        if (0 === \count($flags)) {
            return FlaggedEnum::NONE;
        }

        $bitmask = 0;
        foreach ($flags as $flag) {
            if (!\is_int($flag)) {
                throw new TransformationFailedException(sprintf(
                    'Expected array of integers. Got a "%s" inside.',
                    \is_object($flag) ? \get_class($flag) : \gettype($flag)
                ));
            }
            $bitmask |= $flag;
        }

        if (!$this->isAcceptableValueForEnum($bitmask)) {
            throw new TransformationFailedException(sprintf(
                'Invalid bitmask %s for "%s" flagged enum.',
                $bitmask,
                $this->enumClass
            ));
        }

        return $bitmask;
    }
1228025
public function reverseTransform($value)
    {
        if (null === $value) {
            return null;
        }

        $repo = $this->em->getRepository($this->className);
        $entity = $repo->find($value);

        if (!$entity) {
            return null;
        }

        return $entity;
    }
1222460
function reverse ($this, opts) {
            if (opts.debug) console.time("blast reversal");

            var skippedDescendantRoot = false;

            $this
                .removeClass(NAME + "-root")
                .removeAttr("aria-label")
                .find("." + NAME)
                    .each(function () {
                        var $this = $(this);
                        /* Do not reverse Blast on descendant root elements. (Before you can reverse Blast on an element, you must reverse Blast on any parent elements that have been Blasted.) */
                        if (!$this.closest("." + NAME + "-root").length) {
                            var thisParentNode = this.parentNode;
                            
                            /* This triggers some sort of node layout, thereby solving a node normalization bug in <=IE7 for reasons unknown. If you know the specific reason, tweet me: @Shapiro. */
                            if (IE <= 7) (thisParentNode.firstChild.nodeName);

                            /* Strip the HTML tags off of the wrapper elements by replacing the elements with their child node's text. */
                            thisParentNode.replaceChild(this.firstChild, this);

                            /* Normalize() parents to remove empty text nodes and concatenate sibling text nodes. (This cleans up the DOM after our manipulation.) */
                            thisParentNode.normalize();
                        } else {
                            skippedDescendantRoot = true;
                        }
                    });

            /* Zepto core doesn't include cache-based $.data(), so we mimic data-attr removal by setting it to undefined. */
            if (window.Zepto) {
                $this.data(NAME, undefined);
            } else {
                $this.removeData(NAME);
            }

            if (opts.debug) {
                console.log(NAME + ": Reversed Blast" + ($this.attr("id") ? " on #" + $this.attr("id") + "." : ".") + (skippedDescendantRoot ? " Skipped reversal on the children of one or more descendant root elements." : ""));
                console.timeEnd("blast reversal");
            }
        }
1286006
public function disable($code)
    {
        $promocode = Promocode::byCode($code)->first();

        if ($promocode === null) {
            throw new InvalidPromocodeException;
        }

        $promocode->expires_at = Carbon::now();

        return $promocode->save();
    }
949961
public function reverse() {
		if($this->reverseRelation !== null)
			return $this->reverseRelation;

		$origEntityName = $this->entityClass;
		$entityName = preg_replace('/^\\\/', '', $origEntityName);

		$relationDefinition = $this->getTargetDefinition();
		$name = $this->name;

		$rev_relations = [];
		foreach($this->dataMapper->relations($relationDefinition) as $rev_rel_name=>$rev_rel) {
			if($rev_rel->isPolymorphic()) {
				if(in_array($entityName, $rev_rel->get('entities'))) {
					if($this->get('for') !== null && $this->get('for') !== $rev_rel_name)
						continue;
					if($rev_rel->get('for') !== null && $rev_rel->get('for') !== $name)
						continue;
					$rev_relations[] = $rev_rel;
				}
			}
			else {
				$relEntityClass = preg_replace('/^\\\/', '', $rev_rel->get('entity'));
				if($relEntityClass === $entityName || $this->get('as') === $rev_rel->get('entity')) {
					if($rev_rel_name === $name)
						continue;
					if($this->get('for') !== null && $this->get('for') !== $rev_rel_name)
						continue;
					if($rev_rel->get('for') !== null && $rev_rel->get('for') !== $name)
						continue;
					$rev_relations[] = $rev_rel;
				}
			}
		}

		if(count($rev_relations) == 0)
			throw new \Exception('No reverse relation for '.$entityName.': '.$name);
		elseif(count($rev_relations) > 1)
			throw new \Exception('Multiple reverse relations for '.$entityName.': '.$name);
		else {
			$this->reverseRelation = $rev_relations[0];
			return $rev_relations[0];
		}
	}
376734
public function setReverse($value)
    {
        if ($value != null) {
            $this->_params['reverse'] = $value;
        } else {
            unset($this->_params['reverse']);
        }
        return $this;
    }
1279946
final protected function _refund($a) {
		$ii = $this->ii(); /** @var OP $ii */
		/**
		 * 2016-03-17, 2017-11-11
		 * Despite of its name, @uses \Magento\Sales\Model\Order\Payment::getAuthorizationTransaction()
		 * simply returns the previous transaction,
		 * and it can be not only an `authorization` transaction,
		 * but a transaction of another type (e.g. `payment`) too.
		 *		public function getAuthorizationTransaction() {
		 *			return $this->transactionManager->getAuthorizationTransaction(
		 *				$this->getParentTransactionId(),
		 *				$this->getId(),
		 *				$this->getOrder()->getId()
		 *			);
		 *		}
		 * The code is the same in Magento 2.0.0 - 2.2.1:
		 * https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Sales/Model/Order/Payment.php#L1242-#L1253
		 * https://github.com/magento/magento2/blob/2.2.1/app/code/Magento/Sales/Model/Order/Payment.php#L1316-L1327
		 * @see \Magento\Sales\Model\Order\Payment\Transaction\Manager::getAuthorizationTransaction()
		 *	public function getAuthorizationTransaction($parentTransactionId, $paymentId, $orderId) {
		 *		$transaction = false;
		 *		if ($parentTransactionId) {
		 *			$transaction = $this->transactionRepository->getByTransactionId(
		 *				$parentTransactionId,
		 *				$paymentId,
		 *				$orderId
		 *			);
		 *		}
		 *		return $transaction ?: $this->transactionRepository->getByTransactionType(
		 *			Transaction::TYPE_AUTH,
		 *			$paymentId,
		 *			$orderId
		 *		);
		 *	}
		 * The code is the same in Magento 2.0.0 - 2.2.1:
		 * https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Sales/Model/Order/Payment/Transaction/Manager.php#L31-L47
		 * https://github.com/magento/magento2/blob/2.2.1/app/code/Magento/Sales/Model/Order/Payment/Transaction/Manager.php#L31-L47
		 * It is exactly what we need,
		 * because the module can be set up to capture payments without a preliminary authorization.
		 */
		if ($tPrev = $ii->getAuthorizationTransaction() /** @var T|false $tPrev */) {
			$id = $this->i2e($tPrev->getTxnId()); /** @var string $id */
			// 2016-03-24
			// Credit Memo и Invoice отсутствуют в сценарии Authorize / Capture
			// и присутствуют в сценарии Capture / Refund.
			$cm = $ii->getCreditmemo(); /** @var CM|null $cm */
			$fc = $this->fCharge(); /** @var fCharge $fc */
			$resp = $cm ? $fc->refund($id, $this->amountFormat($a)) : $fc->void($id); /** @var object $resp */
			$this->transInfo($resp);
			$ii->setTransactionId($this->e2i($id, $cm ? Ev::T_REFUND : 'void'));
			if ($cm) {
				/**
				 * 2017-01-19
				 * Записаваем идентификатор операции в БД,
				 * чтобы затем, при обработке оповещений от платёжной системы,
				 * проверять, не было ли это оповещение инициировано нашей же операцией,
				 * и если было, то не обрабатывать его повторно:
				 * @see \Df\Payment\W\Strategy\Refund::_handle()
				 * https://github.com/mage2pro/core/blob/1.12.16/StripeClone/WebhookStrategy/Charge/Refunded.php?ts=4#L21-L23
				 */
				dfp_container_add($this->ii(), self::II_TRANS, fRefund::s($this)->transId($resp));
			}
		}
	}
1095212
public function setInverse($inverse)
    {
        if (!is_bool($inverse)) {
            throw new \InvalidArgumentException('The attribute inverse on the class Attribute has to be boolean (' . gettype($inverse) . ('object' === gettype($inverse) ? ' ' . get_class($inverse) : '') . ' given).');
        }

        $this->inverse = $inverse;

        return $this;
    }