public function willApplyCharge(PhabricatorUser $actor, PhortunePaymentProvider $provider, PhortunePaymentMethod $method = null) { $account = $this->getAccount(); $charge = PhortuneCharge::initializeNewCharge()->setAccountPHID($account->getPHID())->setCartPHID($this->getPHID())->setAuthorPHID($actor->getPHID())->setMerchantPHID($this->getMerchant()->getPHID())->setProviderPHID($provider->getProviderConfig()->getPHID())->setAmountAsCurrency($this->getTotalPriceAsCurrency()); if ($method) { $charge->setPaymentMethodPHID($method->getPHID()); } $this->openTransaction(); $this->beginReadLocking(); $copy = clone $this; $copy->reload(); if ($copy->getStatus() !== self::STATUS_READY) { throw new Exception(pht('Cart has wrong status ("%s") to call %s, expected "%s".', $copy->getStatus(), 'willApplyCharge()', self::STATUS_READY)); } $charge->save(); $this->setStatus(self::STATUS_PURCHASING)->save(); $this->endReadLocking(); $this->saveTransaction(); return $charge; }