1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-19 05:12:41 +01:00

Implement refunds for Balanced in Phortune

Summary: Ref T2787. Does refunds for Balanced.

Test Plan: {F215205}

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T2787

Differential Revision: https://secure.phabricator.com/D10665
This commit is contained in:
epriestley 2014-10-08 15:33:36 -07:00
parent 1e8c314c81
commit f4604ae147

View file

@ -182,8 +182,36 @@ final class PhortuneBalancedPaymentProvider extends PhortunePaymentProvider {
protected function executeRefund(
PhortuneCharge $charge,
PhortuneCharge $refund) {
// TODO: Implement.
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';
$debit_uri = $charge->getMetadataValue('balanced.debitURI');
if (!$debit_uri) {
throw new Exception(pht('No Balanced debit URI!'));
}
$refund_cents = $refund
->getAmountAsCurrency()
->negate()
->getValueInUSDCents();
$params = array(
'amount' => $refund_cents,
);
try {
Balanced\Settings::$api_key = $this->getSecretKey();
$balanced_debit = Balanced\Debit::get($debit_uri);
$balanced_refund = $balanced_debit->refunds->create($params);
} catch (RESTful\Exceptions\HTTPError $error) {
throw new Exception($error->response->body->description);
}
$refund->setMetadataValue('balanced.refundURI', $balanced_refund->uri);
$refund->save();
}
private function getMarketplaceID() {
@ -217,6 +245,7 @@ final class PhortuneBalancedPaymentProvider extends PhortunePaymentProvider {
/**
* @phutil-external-symbol class Balanced\Card
* @phutil-external-symbol class Balanced\Debit
* @phutil-external-symbol class Balanced\Settings
* @phutil-external-symbol class Balanced\Marketplace
* @phutil-external-symbol class Balanced\APIKey