private function chargeSubscription(PhabricatorUser $viewer, PhortuneSubscription $subscription, PhortuneCart $cart) { $issues = array(); if (!$subscription->getDefaultPaymentMethodPHID()) { $issues[] = pht('There is no payment method associated with this subscription, so ' . 'it could not be billed automatically. Add a default payment method ' . 'to enable automatic billing.'); return $issues; } $method = id(new PhortunePaymentMethodQuery())->setViewer($viewer)->withPHIDs(array($subscription->getDefaultPaymentMethodPHID()))->executeOne(); if (!$method) { $issues[] = pht('The payment method associated with this subscription is invalid ' . 'or out of date, so it could not be automatically billed. Update ' . 'the default payment method to enable automatic billing.'); return $issues; } $provider = $method->buildPaymentProvider(); $charge = $cart->willApplyCharge($viewer, $provider, $method); try { $provider->applyCharge($method, $charge); } catch (Exception $ex) { $cart->didFailCharge($charge); $issues[] = pht('Automatic billing failed: %s', $ex->getMessage()); return $issues; } $cart->didApplyCharge($charge); }