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:
parent
1e8c314c81
commit
f4604ae147
1 changed files with 31 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue