Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15413963
D10645.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D10645.id.diff
View Options
diff --git a/src/applications/phortune/currency/PhortuneCurrency.php b/src/applications/phortune/currency/PhortuneCurrency.php
--- a/src/applications/phortune/currency/PhortuneCurrency.php
+++ b/src/applications/phortune/currency/PhortuneCurrency.php
@@ -121,6 +121,13 @@
return $this->currency;
}
+ public function getValueInUSDCents() {
+ if ($this->currency !== 'USD') {
+ throw new Exception(pht('Unexpected currency!'));
+ }
+ return $this->value;
+ }
+
private static function throwFormatException($string) {
throw new Exception("Invalid currency format ('{$string}').");
}
diff --git a/src/applications/phortune/provider/PhortuneBalancedPaymentProvider.php b/src/applications/phortune/provider/PhortuneBalancedPaymentProvider.php
--- a/src/applications/phortune/provider/PhortuneBalancedPaymentProvider.php
+++ b/src/applications/phortune/provider/PhortuneBalancedPaymentProvider.php
@@ -40,7 +40,43 @@
protected function executeCharge(
PhortunePaymentMethod $method,
PhortuneCharge $charge) {
- throw new PhortuneNotImplementedException($this);
+
+ $root = dirname(phutil_get_library_root('phabricator'));
+ require_once $root.'/externals/httpful/bootstrap.php';
+ require_once $root.'/externals/restful/bootstrap.php';
+ require_once $root.'/externals/balanced-php/bootstrap.php';
+
+ $price = $charge->getAmountAsCurrency();
+
+ // Build the string which will appear on the credit card statement.
+ $charge_as = new PhutilURI(PhabricatorEnv::getProductionURI('/'));
+ $charge_as = $charge_as->getDomain();
+ $charge_as = id(new PhutilUTF8StringTruncator())
+ ->setMaximumBytes(22)
+ ->setTerminator('')
+ ->truncateString($charge_as);
+
+ try {
+ Balanced\Settings::$api_key = $this->getSecretKey();
+ $card = Balanced\Card::get($method->getMetadataValue('balanced.cardURI'));
+ $debit = $card->debit($price->getValueInUSDCents(), $charge_as);
+ } catch (RESTful\Exceptions\HTTPError $error) {
+ // NOTE: This exception doesn't print anything meaningful if it escapes
+ // to top level. Replace it with something slightly readable.
+ throw new Exception($error->response->body->description);
+ }
+
+ $expect_status = 'succeeded';
+ if ($debit->status !== $expect_status) {
+ throw new Exception(
+ pht(
+ 'Debit failed, expected "%s", got "%s".',
+ $expect_status,
+ $debit->status));
+ }
+
+ $charge->setMetadataValue('balanced.debitURI', $debit->uri);
+ $charge->save();
}
private function getMarketplaceURI() {
diff --git a/src/applications/phortune/provider/PhortuneStripePaymentProvider.php b/src/applications/phortune/provider/PhortuneStripePaymentProvider.php
--- a/src/applications/phortune/provider/PhortuneStripePaymentProvider.php
+++ b/src/applications/phortune/provider/PhortuneStripePaymentProvider.php
@@ -52,7 +52,7 @@
$secret_key = $this->getSecretKey();
$params = array(
- 'amount' => $price->getValue(),
+ 'amount' => $price->getValueInUSDCents(),
'currency' => $price->getCurrency(),
'customer' => $method->getMetadataValue('stripe.customerID'),
'description' => $charge->getPHID(),
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Mar 20, 10:14 PM (1 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7350439
Default Alt Text
D10645.id.diff (3 KB)
Attached To
Mode
D10645: Give Balanced provider complete workflow logic in Phortune
Attached
Detach File
Event Timeline
Log In to Comment