public final function applyCharge(PhortunePaymentMethod $payment_method, PhortuneCharge $charge)
 {
     $charge->setStatus(PhortuneCharge::STATUS_CHARGING);
     $charge->save();
     $this->executeCharge($payment_method, $charge);
     $charge->setStatus(PhortuneCharge::STATUS_CHARGED);
     $charge->save();
 }
示例#2
0
 public function didFailRefund(PhortuneCharge $charge, PhortuneCharge $refund)
 {
     $refund->setStatus(PhortuneCharge::STATUS_FAILED);
     $this->openTransaction();
     $this->beginReadLocking();
     $copy = clone $charge;
     $copy->reload();
     if ($charge->getRefundingPHID() !== $refund->getPHID()) {
         throw new Exception(pht('Charge is in the wrong refunding state!'));
     }
     $charge->setRefundingPHID(null);
     $charge->save();
     $refund->save();
     $this->endReadLocking();
     $this->saveTransaction();
 }
 protected function executeRefund(PhortuneCharge $charge, PhortuneCharge $refund)
 {
     $this->loadStripeAPILibraries();
     $charge_id = $charge->getMetadataValue('stripe.chargeID');
     if (!$charge_id) {
         throw new Exception(pht('Unable to refund charge; no Stripe chargeID!'));
     }
     $refund_cents = $refund->getAmountAsCurrency()->negate()->getValueInUSDCents();
     $secret_key = $this->getSecretKey();
     $params = array('amount' => $refund_cents);
     $stripe_charge = Stripe_Charge::retrieve($charge_id, $secret_key);
     $stripe_refund = $stripe_charge->refunds->create($params);
     $id = $stripe_refund->id;
     if (!$id) {
         throw new Exception(pht('Stripe refund call did not return an ID!'));
     }
     $charge->setMetadataValue('stripe.refundID', $id);
     $charge->save();
 }