protected function loadPage() { $table = new PhortuneCharge(); $conn = $table->establishConnection('r'); $rows = queryfx_all($conn, 'SELECT charge.* FROM %T charge %Q %Q %Q', $table->getTableName(), $this->buildWhereClause($conn), $this->buildOrderClause($conn), $this->buildLimitClause($conn)); return $table->loadAllFromArray($rows); }
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(); }
/** * @phutil-external-symbol class Stripe_Charge */ protected function executeCharge(PhortunePaymentMethod $method, PhortuneCharge $charge) { $root = dirname(phutil_get_library_root('phabricator')); require_once $root . '/externals/stripe-php/lib/Stripe.php'; $secret_key = $this->getSecretKey(); $params = array('amount' => $charge->getAmountInCents(), 'currency' => 'usd', 'customer' => $method->getMetadataValue('stripe.customerID'), 'description' => $charge->getPHID(), 'capture' => true); $stripe_charge = Stripe_Charge::create($params, $secret_key); $id = $stripe_charge->id; if (!$id) { throw new Exception('Stripe charge call did not return an ID!'); } $charge->setMetadataValue('stripe.chargeID', $id); }
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(); }
public function updateCharge(PhortuneCharge $charge) { $transaction_id = $charge->getMetadataValue('paypal.transactionID'); if (!$transaction_id) { throw new Exception(pht('Charge has no transaction ID!')); } $params = array('TRANSACTIONID' => $transaction_id); $result = $this->newPaypalAPICall()->setRawPayPalQuery('GetTransactionDetails', $params)->resolve(); $is_charge = false; $is_fail = false; switch ($result['PAYMENTSTATUS']) { case 'Processed': case 'Completed': case 'Completed-Funds-Held': $is_charge = true; break; case 'Partially-Refunded': case 'Refunded': case 'Reversed': case 'Canceled-Reversal': // TODO: Handle these. return; case 'In-Progress': case 'Pending': // TODO: Also handle these better? return; case 'Denied': case 'Expired': case 'Failed': case 'None': case 'Voided': default: $is_fail = true; break; } if ($charge->getStatus() == PhortuneCharge::STATUS_HOLD) { $cart = $charge->getCart(); $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); if ($is_charge) { $cart->didApplyCharge($charge); } else { if ($is_fail) { $cart->didFailCharge($charge); } } unset($unguarded); } }
private function getWePayCheckoutID(PhortuneCharge $charge) { $checkout_id = $charge->getMetadataValue('wepay.checkoutID'); if ($checkout_id === null) { throw new Exception(pht('No WePay Checkout ID present on charge!')); } return $checkout_id; }
public function updateCharge(PhortuneCharge $charge) { $this->loadStripeAPILibraries(); $charge_id = $charge->getMetadataValue('stripe.chargeID'); if (!$charge_id) { throw new Exception(pht('Unable to update charge; no Stripe chargeID!')); } $secret_key = $this->getSecretKey(); $stripe_charge = Stripe_Charge::retrieve($charge_id, $secret_key); // TODO: Deal with disputes / chargebacks / surprising refunds. }