@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Give Balanced provider complete workflow logic in Phortune

Summary: Ref T2787. Like Stripe, this one is pretty easy to get working correctly on the "good" path and fataling out in a safe way on bad paths.

Test Plan: Funded an initiative with Balanced.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T2787

Differential Revision: https://secure.phabricator.com/D10645

+45 -2
+7
src/applications/phortune/currency/PhortuneCurrency.php
··· 121 121 return $this->currency; 122 122 } 123 123 124 + public function getValueInUSDCents() { 125 + if ($this->currency !== 'USD') { 126 + throw new Exception(pht('Unexpected currency!')); 127 + } 128 + return $this->value; 129 + } 130 + 124 131 private static function throwFormatException($string) { 125 132 throw new Exception("Invalid currency format ('{$string}')."); 126 133 }
+37 -1
src/applications/phortune/provider/PhortuneBalancedPaymentProvider.php
··· 40 40 protected function executeCharge( 41 41 PhortunePaymentMethod $method, 42 42 PhortuneCharge $charge) { 43 - throw new PhortuneNotImplementedException($this); 43 + 44 + $root = dirname(phutil_get_library_root('phabricator')); 45 + require_once $root.'/externals/httpful/bootstrap.php'; 46 + require_once $root.'/externals/restful/bootstrap.php'; 47 + require_once $root.'/externals/balanced-php/bootstrap.php'; 48 + 49 + $price = $charge->getAmountAsCurrency(); 50 + 51 + // Build the string which will appear on the credit card statement. 52 + $charge_as = new PhutilURI(PhabricatorEnv::getProductionURI('/')); 53 + $charge_as = $charge_as->getDomain(); 54 + $charge_as = id(new PhutilUTF8StringTruncator()) 55 + ->setMaximumBytes(22) 56 + ->setTerminator('') 57 + ->truncateString($charge_as); 58 + 59 + try { 60 + Balanced\Settings::$api_key = $this->getSecretKey(); 61 + $card = Balanced\Card::get($method->getMetadataValue('balanced.cardURI')); 62 + $debit = $card->debit($price->getValueInUSDCents(), $charge_as); 63 + } catch (RESTful\Exceptions\HTTPError $error) { 64 + // NOTE: This exception doesn't print anything meaningful if it escapes 65 + // to top level. Replace it with something slightly readable. 66 + throw new Exception($error->response->body->description); 67 + } 68 + 69 + $expect_status = 'succeeded'; 70 + if ($debit->status !== $expect_status) { 71 + throw new Exception( 72 + pht( 73 + 'Debit failed, expected "%s", got "%s".', 74 + $expect_status, 75 + $debit->status)); 76 + } 77 + 78 + $charge->setMetadataValue('balanced.debitURI', $debit->uri); 79 + $charge->save(); 44 80 } 45 81 46 82 private function getMarketplaceURI() {
+1 -1
src/applications/phortune/provider/PhortuneStripePaymentProvider.php
··· 52 52 53 53 $secret_key = $this->getSecretKey(); 54 54 $params = array( 55 - 'amount' => $price->getValue(), 55 + 'amount' => $price->getValueInUSDCents(), 56 56 'currency' => $price->getCurrency(), 57 57 'customer' => $method->getMetadataValue('stripe.customerID'), 58 58 'description' => $charge->getPHID(),