mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 08:42:41 +01:00
Adjust payment workflows to deal with merchants and configurable providers in Phortune
Summary: Ref T2787. Builds on D10649 by rebining existing objects (carts, charges, etc) to merchantPHIDs and providerPHIDs instead of an implicit global merchant and weird global artifacts (providerType / providerKey). Basically: - When you create something that users can pay for, you specify a merchant to control where the payment goes. - Accounts are install-wide, but payment methods are bound to merchants. This seems to do a reasonable job of balancing usability and technical concerns. - Replace a bunch of weird links between objects with standard PHIDs. - Improve "add payment method" flow. Test Plan: Went through the Fund flow with Stripe and WePay, funding an initiative. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T2787 Differential Revision: https://secure.phabricator.com/D10652
This commit is contained in:
parent
9aa5a8cb7b
commit
9c4b8a0fb2
21 changed files with 403 additions and 78 deletions
2
resources/sql/autopatches/20141007.fundmerchant.sql
Normal file
2
resources/sql/autopatches/20141007.fundmerchant.sql
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE {$NAMESPACE}_fund.fund_initiative
|
||||||
|
ADD merchantPHID VARBINARY(64);
|
|
@ -0,0 +1,5 @@
|
||||||
|
ALTER TABLE {$NAMESPACE}_phortune.phortune_cart
|
||||||
|
ADD merchantPHID VARBINARY(64) NOT NULL;
|
||||||
|
|
||||||
|
ALTER TABLE {$NAMESPACE}_phortune.phortune_cart
|
||||||
|
ADD KEY `key_merchant` (merchantPHID);
|
16
resources/sql/autopatches/20141007.phortunecharge.sql
Normal file
16
resources/sql/autopatches/20141007.phortunecharge.sql
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
TRUNCATE TABLE {$NAMESPACE}_phortune.phortune_charge;
|
||||||
|
|
||||||
|
ALTER TABLE {$NAMESPACE}_phortune.phortune_charge
|
||||||
|
DROP paymentProviderKey;
|
||||||
|
|
||||||
|
ALTER TABLE {$NAMESPACE}_phortune.phortune_charge
|
||||||
|
ADD merchantPHID VARBINARY(64) NOT NULL;
|
||||||
|
|
||||||
|
ALTER TABLE {$NAMESPACE}_phortune.phortune_charge
|
||||||
|
ADD providerPHID VARBINARY(64) NOT NULL;
|
||||||
|
|
||||||
|
ALTER TABLE {$NAMESPACE}_phortune.phortune_charge
|
||||||
|
ADD KEY `key_merchant` (merchantPHID);
|
||||||
|
|
||||||
|
ALTER TABLE {$NAMESPACE}_phortune.phortune_charge
|
||||||
|
ADD KEY `key_provider` (providerPHID);
|
16
resources/sql/autopatches/20141007.phortunepayment.sql
Normal file
16
resources/sql/autopatches/20141007.phortunepayment.sql
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
TRUNCATE TABLE {$NAMESPACE}_phortune.phortune_paymentmethod;
|
||||||
|
|
||||||
|
ALTER TABLE {$NAMESPACE}_phortune.phortune_paymentmethod
|
||||||
|
DROP providerType;
|
||||||
|
|
||||||
|
ALTER TABLE {$NAMESPACE}_phortune.phortune_paymentmethod
|
||||||
|
DROP providerDomain;
|
||||||
|
|
||||||
|
ALTER TABLE {$NAMESPACE}_phortune.phortune_paymentmethod
|
||||||
|
ADD merchantPHID VARBINARY(64) NOT NULL;
|
||||||
|
|
||||||
|
ALTER TABLE {$NAMESPACE}_phortune.phortune_paymentmethod
|
||||||
|
ADD providerPHID VARBINARY(64) NOT NULL;
|
||||||
|
|
||||||
|
ALTER TABLE {$NAMESPACE}_phortune.phortune_paymentmethod
|
||||||
|
ADD KEY `key_merchant` (merchantPHID, accountPHID);
|
|
@ -21,6 +21,14 @@ final class FundInitiativeBackController
|
||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$merchant = id(new PhortuneMerchantQuery())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->withPHIDs(array($initiative->getMerchantPHID()))
|
||||||
|
->executeOne();
|
||||||
|
if (!$merchant) {
|
||||||
|
return new Aphront404Response();
|
||||||
|
}
|
||||||
|
|
||||||
$initiative_uri = '/'.$initiative->getMonogram();
|
$initiative_uri = '/'.$initiative->getMonogram();
|
||||||
|
|
||||||
if ($initiative->isClosed()) {
|
if ($initiative->isClosed()) {
|
||||||
|
@ -73,7 +81,7 @@ final class FundInitiativeBackController
|
||||||
$cart_implementation = id(new FundBackerCart())
|
$cart_implementation = id(new FundBackerCart())
|
||||||
->setInitiative($initiative);
|
->setInitiative($initiative);
|
||||||
|
|
||||||
$cart = $account->newCart($viewer, $cart_implementation);
|
$cart = $account->newCart($viewer, $cart_implementation, $merchant);
|
||||||
|
|
||||||
$purchase = $cart->newPurchase($viewer, $product);
|
$purchase = $cart->newPurchase($viewer, $product);
|
||||||
$purchase
|
$purchase
|
||||||
|
|
|
@ -48,6 +48,9 @@ final class FundInitiativeEditController
|
||||||
$e_name = true;
|
$e_name = true;
|
||||||
$v_name = $initiative->getName();
|
$v_name = $initiative->getName();
|
||||||
|
|
||||||
|
$e_merchant = null;
|
||||||
|
$v_merchant = $initiative->getMerchantPHID();
|
||||||
|
|
||||||
$v_desc = $initiative->getDescription();
|
$v_desc = $initiative->getDescription();
|
||||||
|
|
||||||
if ($is_new) {
|
if ($is_new) {
|
||||||
|
@ -65,10 +68,12 @@ final class FundInitiativeEditController
|
||||||
$v_desc = $request->getStr('description');
|
$v_desc = $request->getStr('description');
|
||||||
$v_view = $request->getStr('viewPolicy');
|
$v_view = $request->getStr('viewPolicy');
|
||||||
$v_edit = $request->getStr('editPolicy');
|
$v_edit = $request->getStr('editPolicy');
|
||||||
|
$v_merchant = $request->getStr('merchantPHID');
|
||||||
$v_projects = $request->getArr('projects');
|
$v_projects = $request->getArr('projects');
|
||||||
|
|
||||||
$type_name = FundInitiativeTransaction::TYPE_NAME;
|
$type_name = FundInitiativeTransaction::TYPE_NAME;
|
||||||
$type_desc = FundInitiativeTransaction::TYPE_DESCRIPTION;
|
$type_desc = FundInitiativeTransaction::TYPE_DESCRIPTION;
|
||||||
|
$type_merchant = FundInitiativeTransaction::TYPE_MERCHANT;
|
||||||
$type_view = PhabricatorTransactions::TYPE_VIEW_POLICY;
|
$type_view = PhabricatorTransactions::TYPE_VIEW_POLICY;
|
||||||
$type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY;
|
$type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY;
|
||||||
|
|
||||||
|
@ -82,6 +87,10 @@ final class FundInitiativeEditController
|
||||||
->setTransactionType($type_desc)
|
->setTransactionType($type_desc)
|
||||||
->setNewValue($v_desc);
|
->setNewValue($v_desc);
|
||||||
|
|
||||||
|
$xactions[] = id(new FundInitiativeTransaction())
|
||||||
|
->setTransactionType($type_merchant)
|
||||||
|
->setNewValue($v_merchant);
|
||||||
|
|
||||||
$xactions[] = id(new FundInitiativeTransaction())
|
$xactions[] = id(new FundInitiativeTransaction())
|
||||||
->setTransactionType($type_view)
|
->setTransactionType($type_view)
|
||||||
->setNewValue($v_view);
|
->setNewValue($v_view);
|
||||||
|
@ -110,6 +119,7 @@ final class FundInitiativeEditController
|
||||||
$validation_exception = $ex;
|
$validation_exception = $ex;
|
||||||
|
|
||||||
$e_name = $ex->getShortMessage($type_name);
|
$e_name = $ex->getShortMessage($type_name);
|
||||||
|
$e_merchant = $ex->getShortMessage($type_merchant);
|
||||||
|
|
||||||
$initiative->setViewPolicy($v_view);
|
$initiative->setViewPolicy($v_view);
|
||||||
$initiative->setEditPolicy($v_edit);
|
$initiative->setEditPolicy($v_edit);
|
||||||
|
@ -127,6 +137,45 @@ final class FundInitiativeEditController
|
||||||
$project_handles = array();
|
$project_handles = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$merchants = id(new PhortuneMerchantQuery())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->requireCapabilities(
|
||||||
|
array(
|
||||||
|
PhabricatorPolicyCapability::CAN_VIEW,
|
||||||
|
PhabricatorPolicyCapability::CAN_EDIT,
|
||||||
|
))
|
||||||
|
->execute();
|
||||||
|
|
||||||
|
$merchant_options = array();
|
||||||
|
foreach ($merchants as $merchant) {
|
||||||
|
$merchant_options[$merchant->getPHID()] = pht(
|
||||||
|
'Merchant %d %s',
|
||||||
|
$merchant->getID(),
|
||||||
|
$merchant->getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($v_merchant && empty($merchant_options[$v_merchant])) {
|
||||||
|
$merchant_options = array(
|
||||||
|
$v_merchant => pht('(Restricted Merchant)'),
|
||||||
|
) + $merchant_options;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$merchant_options) {
|
||||||
|
return $this->newDialog()
|
||||||
|
->setTitle(pht('No Valid Phortune Merchant Accounts'))
|
||||||
|
->appendParagraph(
|
||||||
|
pht(
|
||||||
|
'You do not control any merchant accounts which can receive '.
|
||||||
|
'payments from this initiative. When you create an initiative, '.
|
||||||
|
'you need to specify a merchant account where funds will be paid '.
|
||||||
|
'to.'))
|
||||||
|
->appendParagraph(
|
||||||
|
pht(
|
||||||
|
'Create a merchant account in the Phortune application before '.
|
||||||
|
'creating an initiative in Fund.'))
|
||||||
|
->addCancelButton($this->getApplicationURI());
|
||||||
|
}
|
||||||
|
|
||||||
$form = id(new AphrontFormView())
|
$form = id(new AphrontFormView())
|
||||||
->setUser($viewer)
|
->setUser($viewer)
|
||||||
->appendChild(
|
->appendChild(
|
||||||
|
@ -135,6 +184,13 @@ final class FundInitiativeEditController
|
||||||
->setLabel(pht('Name'))
|
->setLabel(pht('Name'))
|
||||||
->setValue($v_name)
|
->setValue($v_name)
|
||||||
->setError($e_name))
|
->setError($e_name))
|
||||||
|
->appendChild(
|
||||||
|
id(new AphrontFormSelectControl())
|
||||||
|
->setName('merchantPHID')
|
||||||
|
->setLabel(pht('Pay To Merchant'))
|
||||||
|
->setValue($v_merchant)
|
||||||
|
->setError($e_merchant)
|
||||||
|
->setOptions($merchant_options))
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new PhabricatorRemarkupControl())
|
id(new PhabricatorRemarkupControl())
|
||||||
->setName('description')
|
->setName('description')
|
||||||
|
|
|
@ -18,6 +18,7 @@ final class FundInitiativeEditor
|
||||||
$types[] = FundInitiativeTransaction::TYPE_DESCRIPTION;
|
$types[] = FundInitiativeTransaction::TYPE_DESCRIPTION;
|
||||||
$types[] = FundInitiativeTransaction::TYPE_STATUS;
|
$types[] = FundInitiativeTransaction::TYPE_STATUS;
|
||||||
$types[] = FundInitiativeTransaction::TYPE_BACKER;
|
$types[] = FundInitiativeTransaction::TYPE_BACKER;
|
||||||
|
$types[] = FundInitiativeTransaction::TYPE_MERCHANT;
|
||||||
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
|
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
|
||||||
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
|
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
|
||||||
|
|
||||||
|
@ -36,6 +37,8 @@ final class FundInitiativeEditor
|
||||||
return $object->getStatus();
|
return $object->getStatus();
|
||||||
case FundInitiativeTransaction::TYPE_BACKER:
|
case FundInitiativeTransaction::TYPE_BACKER:
|
||||||
return null;
|
return null;
|
||||||
|
case FundInitiativeTransaction::TYPE_MERCHANT:
|
||||||
|
return $object->getMerchantPHID();
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::getCustomTransactionOldValue($object, $xaction);
|
return parent::getCustomTransactionOldValue($object, $xaction);
|
||||||
|
@ -50,6 +53,7 @@ final class FundInitiativeEditor
|
||||||
case FundInitiativeTransaction::TYPE_DESCRIPTION:
|
case FundInitiativeTransaction::TYPE_DESCRIPTION:
|
||||||
case FundInitiativeTransaction::TYPE_STATUS:
|
case FundInitiativeTransaction::TYPE_STATUS:
|
||||||
case FundInitiativeTransaction::TYPE_BACKER:
|
case FundInitiativeTransaction::TYPE_BACKER:
|
||||||
|
case FundInitiativeTransaction::TYPE_MERCHANT:
|
||||||
return $xaction->getNewValue();
|
return $xaction->getNewValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,6 +71,9 @@ final class FundInitiativeEditor
|
||||||
case FundInitiativeTransaction::TYPE_DESCRIPTION:
|
case FundInitiativeTransaction::TYPE_DESCRIPTION:
|
||||||
$object->setDescription($xaction->getNewValue());
|
$object->setDescription($xaction->getNewValue());
|
||||||
return;
|
return;
|
||||||
|
case FundInitiativeTransaction::TYPE_MERCHANT:
|
||||||
|
$object->setMerchantPHID($xaction->getNewValue());
|
||||||
|
return;
|
||||||
case FundInitiativeTransaction::TYPE_STATUS:
|
case FundInitiativeTransaction::TYPE_STATUS:
|
||||||
$object->setStatus($xaction->getNewValue());
|
$object->setStatus($xaction->getNewValue());
|
||||||
return;
|
return;
|
||||||
|
@ -89,6 +96,7 @@ final class FundInitiativeEditor
|
||||||
case FundInitiativeTransaction::TYPE_NAME:
|
case FundInitiativeTransaction::TYPE_NAME:
|
||||||
case FundInitiativeTransaction::TYPE_DESCRIPTION:
|
case FundInitiativeTransaction::TYPE_DESCRIPTION:
|
||||||
case FundInitiativeTransaction::TYPE_STATUS:
|
case FundInitiativeTransaction::TYPE_STATUS:
|
||||||
|
case FundInitiativeTransaction::TYPE_MERCHANT:
|
||||||
case FundInitiativeTransaction::TYPE_BACKER:
|
case FundInitiativeTransaction::TYPE_BACKER:
|
||||||
// TODO: Maybe we should apply the backer transaction from here?
|
// TODO: Maybe we should apply the backer transaction from here?
|
||||||
return;
|
return;
|
||||||
|
@ -124,6 +132,46 @@ final class FundInitiativeEditor
|
||||||
$errors[] = $error;
|
$errors[] = $error;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case FundInitiativeTransaction::TYPE_MERCHANT:
|
||||||
|
$missing = $this->validateIsEmptyTextField(
|
||||||
|
$object->getName(),
|
||||||
|
$xactions);
|
||||||
|
if ($missing) {
|
||||||
|
$error = new PhabricatorApplicationTransactionValidationError(
|
||||||
|
$type,
|
||||||
|
pht('Required'),
|
||||||
|
pht('Payable merchant is required.'),
|
||||||
|
nonempty(last($xactions), null));
|
||||||
|
|
||||||
|
$error->setIsMissingFieldError(true);
|
||||||
|
$errors[] = $error;
|
||||||
|
} else if ($xactions) {
|
||||||
|
$merchant_phid = last($xactions)->getNewValue();
|
||||||
|
|
||||||
|
// Make sure the actor has permission to edit the merchant they're
|
||||||
|
// selecting. You aren't allowed to send payments to an account you
|
||||||
|
// do not control.
|
||||||
|
$merchants = id(new PhortuneMerchantQuery())
|
||||||
|
->setViewer($this->requireActor())
|
||||||
|
->withPHIDs(array($merchant_phid))
|
||||||
|
->requireCapabilities(
|
||||||
|
array(
|
||||||
|
PhabricatorPolicyCapability::CAN_VIEW,
|
||||||
|
PhabricatorPolicyCapability::CAN_EDIT,
|
||||||
|
))
|
||||||
|
->execute();
|
||||||
|
if (!$merchants) {
|
||||||
|
$error = new PhabricatorApplicationTransactionValidationError(
|
||||||
|
$type,
|
||||||
|
pht('Invalid'),
|
||||||
|
pht(
|
||||||
|
'You must specify a merchant account you control as the '.
|
||||||
|
'recipient of funds from this initiative.'),
|
||||||
|
last($xactions));
|
||||||
|
$errors[] = $error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $errors;
|
return $errors;
|
||||||
|
|
|
@ -13,6 +13,7 @@ final class FundInitiative extends FundDAO
|
||||||
|
|
||||||
protected $name;
|
protected $name;
|
||||||
protected $ownerPHID;
|
protected $ownerPHID;
|
||||||
|
protected $merchantPHID;
|
||||||
protected $description;
|
protected $description;
|
||||||
protected $viewPolicy;
|
protected $viewPolicy;
|
||||||
protected $editPolicy;
|
protected $editPolicy;
|
||||||
|
@ -52,6 +53,7 @@ final class FundInitiative extends FundDAO
|
||||||
'name' => 'text255',
|
'name' => 'text255',
|
||||||
'description' => 'text',
|
'description' => 'text',
|
||||||
'status' => 'text32',
|
'status' => 'text32',
|
||||||
|
'merchantPHID' => 'phid?',
|
||||||
),
|
),
|
||||||
self::CONFIG_KEY_SCHEMA => array(
|
self::CONFIG_KEY_SCHEMA => array(
|
||||||
'key_status' => array(
|
'key_status' => array(
|
||||||
|
|
|
@ -7,6 +7,7 @@ final class FundInitiativeTransaction
|
||||||
const TYPE_DESCRIPTION = 'fund:description';
|
const TYPE_DESCRIPTION = 'fund:description';
|
||||||
const TYPE_STATUS = 'fund:status';
|
const TYPE_STATUS = 'fund:status';
|
||||||
const TYPE_BACKER = 'fund:backer';
|
const TYPE_BACKER = 'fund:backer';
|
||||||
|
const TYPE_MERCHANT = 'fund:merchant';
|
||||||
|
|
||||||
public function getApplicationName() {
|
public function getApplicationName() {
|
||||||
return 'fund';
|
return 'fund';
|
||||||
|
@ -20,6 +21,27 @@ final class FundInitiativeTransaction
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getRequiredHandlePHIDs() {
|
||||||
|
$phids = parent::getRequiredHandlePHIDs();
|
||||||
|
|
||||||
|
$old = $this->getOldValue();
|
||||||
|
$new = $this->getNewValue();
|
||||||
|
|
||||||
|
$type = $this->getTransactionType();
|
||||||
|
switch ($type) {
|
||||||
|
case FundInitiativeTransaction::TYPE_MERCHANT:
|
||||||
|
if ($old) {
|
||||||
|
$phids[] = $old;
|
||||||
|
}
|
||||||
|
if ($new) {
|
||||||
|
$phids[] = $new;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $phids;
|
||||||
|
}
|
||||||
|
|
||||||
public function getTitle() {
|
public function getTitle() {
|
||||||
$author_phid = $this->getAuthorPHID();
|
$author_phid = $this->getAuthorPHID();
|
||||||
$object_phid = $this->getObjectPHID();
|
$object_phid = $this->getObjectPHID();
|
||||||
|
@ -62,6 +84,20 @@ final class FundInitiativeTransaction
|
||||||
return pht(
|
return pht(
|
||||||
'%s backed this initiative.',
|
'%s backed this initiative.',
|
||||||
$this->renderHandleLink($author_phid));
|
$this->renderHandleLink($author_phid));
|
||||||
|
case FundInitiativeTransaction::TYPE_MERCHANT:
|
||||||
|
if ($old === null) {
|
||||||
|
return pht(
|
||||||
|
'%s set this initiative to pay to %s.',
|
||||||
|
$this->renderHandleLink($author_phid),
|
||||||
|
$this->renderHandleLink($new));
|
||||||
|
} else {
|
||||||
|
return pht(
|
||||||
|
'%s changed the merchant receiving funds from this '.
|
||||||
|
'initiative from %s to %s.',
|
||||||
|
$this->renderHandleLink($author_phid),
|
||||||
|
$this->renderHandleLink($old),
|
||||||
|
$this->renderHandleLink($new));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::getTitle();
|
return parent::getTitle();
|
||||||
|
|
|
@ -89,13 +89,7 @@ final class PhortuneAccountViewController extends PhortuneController {
|
||||||
$id = $account->getID();
|
$id = $account->getID();
|
||||||
|
|
||||||
$header = id(new PHUIHeaderView())
|
$header = id(new PHUIHeaderView())
|
||||||
->setHeader(pht('Payment Methods'))
|
->setHeader(pht('Payment Methods'));
|
||||||
->addActionLink(
|
|
||||||
id(new PHUIButtonView())
|
|
||||||
->setTag('a')
|
|
||||||
->setHref($this->getApplicationURI($id.'/card/new/'))
|
|
||||||
->setText(pht('Add Payment Method'))
|
|
||||||
->setIcon(id(new PHUIIconView())->setIconFont('fa-plus')));
|
|
||||||
|
|
||||||
$list = id(new PHUIObjectItemListView())
|
$list = id(new PHUIObjectItemListView())
|
||||||
->setUser($viewer)
|
->setUser($viewer)
|
||||||
|
|
|
@ -23,6 +23,7 @@ final class PhortuneCartCheckoutController
|
||||||
}
|
}
|
||||||
|
|
||||||
$cancel_uri = $cart->getCancelURI();
|
$cancel_uri = $cart->getCancelURI();
|
||||||
|
$merchant = $cart->getMerchant();
|
||||||
|
|
||||||
switch ($cart->getStatus()) {
|
switch ($cart->getStatus()) {
|
||||||
case PhortuneCart::STATUS_BUILDING:
|
case PhortuneCart::STATUS_BUILDING:
|
||||||
|
@ -83,6 +84,7 @@ final class PhortuneCartCheckoutController
|
||||||
$methods = id(new PhortunePaymentMethodQuery())
|
$methods = id(new PhortunePaymentMethodQuery())
|
||||||
->setViewer($viewer)
|
->setViewer($viewer)
|
||||||
->withAccountPHIDs(array($account->getPHID()))
|
->withAccountPHIDs(array($account->getPHID()))
|
||||||
|
->withMerchantPHIDs(array($merchant->getPHID()))
|
||||||
->withStatuses(array(PhortunePaymentMethod::STATUS_ACTIVE))
|
->withStatuses(array(PhortunePaymentMethod::STATUS_ACTIVE))
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
|
@ -142,14 +144,22 @@ final class PhortuneCartCheckoutController
|
||||||
|
|
||||||
$method_control->setError($e_method);
|
$method_control->setError($e_method);
|
||||||
|
|
||||||
$payment_method_uri = $this->getApplicationURI(
|
$account_id = $account->getID();
|
||||||
$account->getID().'/card/new/');
|
|
||||||
|
$payment_method_uri = $this->getApplicationURI("{$account_id}/card/new/");
|
||||||
|
$payment_method_uri = new PhutilURI($payment_method_uri);
|
||||||
|
$payment_method_uri->setQueryParams(
|
||||||
|
array(
|
||||||
|
'merchantID' => $merchant->getID(),
|
||||||
|
'cartID' => $cart->getID(),
|
||||||
|
));
|
||||||
|
|
||||||
$form = id(new AphrontFormView())
|
$form = id(new AphrontFormView())
|
||||||
->setUser($viewer)
|
->setUser($viewer)
|
||||||
->appendChild($method_control);
|
->appendChild($method_control);
|
||||||
|
|
||||||
$add_providers = PhortunePaymentProvider::getProvidersForAddPaymentMethod();
|
$add_providers = $this->loadCreatePaymentMethodProvidersForMerchant(
|
||||||
|
$merchant);
|
||||||
if ($add_providers) {
|
if ($add_providers) {
|
||||||
$new_method = phutil_tag(
|
$new_method = phutil_tag(
|
||||||
'a',
|
'a',
|
||||||
|
@ -178,7 +188,7 @@ final class PhortuneCartCheckoutController
|
||||||
|
|
||||||
$provider_form = null;
|
$provider_form = null;
|
||||||
|
|
||||||
$pay_providers = PhortunePaymentProvider::getProvidersForOneTimePayment();
|
$pay_providers = $this->loadOneTimePaymentProvidersForMerchant($merchant);
|
||||||
if ($pay_providers) {
|
if ($pay_providers) {
|
||||||
$one_time_options = array();
|
$one_time_options = array();
|
||||||
foreach ($pay_providers as $provider) {
|
foreach ($pay_providers as $provider) {
|
||||||
|
|
|
@ -86,4 +86,50 @@ abstract class PhortuneController extends PhabricatorController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function loadEnabledProvidersForMerchant(PhortuneMerchant $merchant) {
|
||||||
|
$viewer = $this->getRequest()->getUser();
|
||||||
|
|
||||||
|
$provider_configs = id(new PhortunePaymentProviderConfigQuery())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->withMerchantPHIDs(array($merchant->getPHID()))
|
||||||
|
->execute();
|
||||||
|
$providers = mpull($provider_configs, 'buildProvider', 'getID');
|
||||||
|
|
||||||
|
foreach ($providers as $key => $provider) {
|
||||||
|
if (!$provider->isEnabled()) {
|
||||||
|
unset($providers[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $providers;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function loadCreatePaymentMethodProvidersForMerchant(
|
||||||
|
PhortuneMerchant $merchant) {
|
||||||
|
|
||||||
|
$providers = $this->loadEnabledProvidersForMerchant($merchant);
|
||||||
|
foreach ($providers as $key => $provider) {
|
||||||
|
if (!$provider->canCreatePaymentMethods()) {
|
||||||
|
unset($providers[$key]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $providers;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function loadOneTimePaymentProvidersForMerchant(
|
||||||
|
PhortuneMerchant $merchant) {
|
||||||
|
|
||||||
|
$providers = $this->loadEnabledProvidersForMerchant($merchant);
|
||||||
|
foreach ($providers as $key => $provider) {
|
||||||
|
if (!$provider->canProcessOneTimePayments()) {
|
||||||
|
unset($providers[$key]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $providers;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,28 +11,36 @@ final class PhortunePaymentMethodCreateController
|
||||||
|
|
||||||
public function processRequest() {
|
public function processRequest() {
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$user = $request->getUser();
|
$viewer = $request->getUser();
|
||||||
|
|
||||||
$account = id(new PhortuneAccountQuery())
|
$account = id(new PhortuneAccountQuery())
|
||||||
->setViewer($user)
|
->setViewer($viewer)
|
||||||
->withIDs(array($this->accountID))
|
->withIDs(array($this->accountID))
|
||||||
->executeOne();
|
->executeOne();
|
||||||
if (!$account) {
|
if (!$account) {
|
||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$merchant = id(new PhortuneMerchantQuery())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->withIDs(array($request->getInt('merchantID')))
|
||||||
|
->executeOne();
|
||||||
|
if (!$merchant) {
|
||||||
|
return new Aphront404Response();
|
||||||
|
}
|
||||||
|
|
||||||
$cancel_uri = $this->getApplicationURI($account->getID().'/');
|
$cancel_uri = $this->getApplicationURI($account->getID().'/');
|
||||||
$account_uri = $this->getApplicationURI($account->getID().'/');
|
$account_uri = $this->getApplicationURI($account->getID().'/');
|
||||||
|
|
||||||
$providers = PhortunePaymentProvider::getProvidersForAddPaymentMethod();
|
$providers = $this->loadCreatePaymentMethodProvidersForMerchant($merchant);
|
||||||
if (!$providers) {
|
if (!$providers) {
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
'There are no payment providers enabled that can add payment '.
|
'There are no payment providers enabled that can add payment '.
|
||||||
'methods.');
|
'methods.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$provider_key = $request->getStr('providerKey');
|
$provider_id = $request->getInt('providerID');
|
||||||
if (empty($providers[$provider_key])) {
|
if (empty($providers[$provider_id])) {
|
||||||
$choices = array();
|
$choices = array();
|
||||||
foreach ($providers as $provider) {
|
foreach ($providers as $provider) {
|
||||||
$choices[] = $this->renderSelectProvider($provider);
|
$choices[] = $this->renderSelectProvider($provider);
|
||||||
|
@ -53,16 +61,16 @@ final class PhortunePaymentMethodCreateController
|
||||||
->addCancelButton($account_uri);
|
->addCancelButton($account_uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
$provider = $providers[$provider_key];
|
$provider = $providers[$provider_id];
|
||||||
|
|
||||||
$errors = array();
|
$errors = array();
|
||||||
if ($request->isFormPost() && $request->getBool('isProviderForm')) {
|
if ($request->isFormPost() && $request->getBool('isProviderForm')) {
|
||||||
$method = id(new PhortunePaymentMethod())
|
$method = id(new PhortunePaymentMethod())
|
||||||
->setAccountPHID($account->getPHID())
|
->setAccountPHID($account->getPHID())
|
||||||
->setAuthorPHID($user->getPHID())
|
->setAuthorPHID($viewer->getPHID())
|
||||||
->setStatus(PhortunePaymentMethod::STATUS_ACTIVE)
|
->setMerchantPHID($merchant->getPHID())
|
||||||
->setProviderType($provider->getProviderType())
|
->setProviderPHID($provider->getProviderConfig()->getPHID())
|
||||||
->setProviderDomain($provider->getProviderDomain());
|
->setStatus(PhortunePaymentMethod::STATUS_ACTIVE);
|
||||||
|
|
||||||
if (!$errors) {
|
if (!$errors) {
|
||||||
$errors = $this->processClientErrors(
|
$errors = $this->processClientErrors(
|
||||||
|
@ -97,12 +105,21 @@ final class PhortunePaymentMethodCreateController
|
||||||
if (!$errors) {
|
if (!$errors) {
|
||||||
$method->save();
|
$method->save();
|
||||||
|
|
||||||
$save_uri = new PhutilURI($account_uri);
|
// If we added this method on a cart flow, return to the cart to
|
||||||
$save_uri->setFragment('payment');
|
// check out.
|
||||||
return id(new AphrontRedirectResponse())->setURI($save_uri);
|
$cart_id = $request->getInt('cartID');
|
||||||
|
if ($cart_id) {
|
||||||
|
$next_uri = $this->getApplicationURI(
|
||||||
|
"cart/{$cart_id}/checkout/?paymentMethodID=".$method->getID());
|
||||||
|
} else {
|
||||||
|
$next_uri = new PhutilURI($account_uri);
|
||||||
|
$next_uri->setFragment('payment');
|
||||||
|
}
|
||||||
|
|
||||||
|
return id(new AphrontRedirectResponse())->setURI($next_uri);
|
||||||
} else {
|
} else {
|
||||||
$dialog = id(new AphrontDialogView())
|
$dialog = id(new AphrontDialogView())
|
||||||
->setUser($user)
|
->setUser($viewer)
|
||||||
->setTitle(pht('Error Adding Payment Method'))
|
->setTitle(pht('Error Adding Payment Method'))
|
||||||
->appendChild(id(new AphrontErrorView())->setErrors($errors))
|
->appendChild(id(new AphrontErrorView())->setErrors($errors))
|
||||||
->addCancelButton($request->getRequestURI());
|
->addCancelButton($request->getRequestURI());
|
||||||
|
@ -114,10 +131,11 @@ final class PhortunePaymentMethodCreateController
|
||||||
$form = $provider->renderCreatePaymentMethodForm($request, $errors);
|
$form = $provider->renderCreatePaymentMethodForm($request, $errors);
|
||||||
|
|
||||||
$form
|
$form
|
||||||
->setUser($user)
|
->setUser($viewer)
|
||||||
->setAction($request->getRequestURI())
|
->setAction($request->getRequestURI())
|
||||||
->setWorkflow(true)
|
->setWorkflow(true)
|
||||||
->addHiddenInput('providerKey', $provider_key)
|
->addHiddenInput('providerID', $provider_id)
|
||||||
|
->addHiddenInput('cartID', $request->getInt('cartID'))
|
||||||
->addHiddenInput('isProviderForm', true)
|
->addHiddenInput('isProviderForm', true)
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormSubmitControl())
|
id(new AphrontFormSubmitControl())
|
||||||
|
@ -145,7 +163,7 @@ final class PhortunePaymentMethodCreateController
|
||||||
PhortunePaymentProvider $provider) {
|
PhortunePaymentProvider $provider) {
|
||||||
|
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$user = $request->getUser();
|
$viewer = $request->getUser();
|
||||||
|
|
||||||
$description = $provider->getPaymentMethodDescription();
|
$description = $provider->getPaymentMethodDescription();
|
||||||
$icon_uri = $provider->getPaymentMethodIcon();
|
$icon_uri = $provider->getPaymentMethodIcon();
|
||||||
|
@ -165,8 +183,8 @@ final class PhortunePaymentMethodCreateController
|
||||||
->setSubtext($details);
|
->setSubtext($details);
|
||||||
|
|
||||||
$form = id(new AphrontFormView())
|
$form = id(new AphrontFormView())
|
||||||
->setUser($user)
|
->setUser($viewer)
|
||||||
->addHiddenInput('providerKey', $provider->getProviderKey())
|
->addHiddenInput('providerID', $provider->getProviderConfig()->getID())
|
||||||
->appendChild($button);
|
->appendChild($button);
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
|
|
|
@ -30,7 +30,7 @@ final class PhortuneMerchantPHIDType extends PhabricatorPHIDType {
|
||||||
|
|
||||||
$id = $merchant->getID();
|
$id = $merchant->getID();
|
||||||
|
|
||||||
$handle->setName(pht('Merchant %d', $id));
|
$handle->setName(pht('Merchant %d %s', $id, $merchant->getName()));
|
||||||
$handle->setURI("/phortune/merchant/{$id}/");
|
$handle->setURI("/phortune/merchant/{$id}/");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,36 +120,6 @@ abstract class PhortunePaymentProvider {
|
||||||
->loadObjects();
|
->loadObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getEnabledProviders() {
|
|
||||||
$providers = self::getAllProviders();
|
|
||||||
foreach ($providers as $key => $provider) {
|
|
||||||
if (!$provider->isEnabled()) {
|
|
||||||
unset($providers[$key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $providers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getProvidersForAddPaymentMethod() {
|
|
||||||
$providers = self::getEnabledProviders();
|
|
||||||
foreach ($providers as $key => $provider) {
|
|
||||||
if (!$provider->canCreatePaymentMethods()) {
|
|
||||||
unset($providers[$key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $providers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getProvidersForOneTimePayment() {
|
|
||||||
$providers = self::getEnabledProviders();
|
|
||||||
foreach ($providers as $key => $provider) {
|
|
||||||
if (!$provider->canProcessOneTimePayments()) {
|
|
||||||
unset($providers[$key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $providers;
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract public function isEnabled();
|
abstract public function isEnabled();
|
||||||
|
|
||||||
abstract public function getPaymentMethodDescription();
|
abstract public function getPaymentMethodDescription();
|
||||||
|
|
|
@ -66,6 +66,21 @@ final class PhortuneCartQuery
|
||||||
$cart->attachAccount($account);
|
$cart->attachAccount($account);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$merchants = id(new PhortuneMerchantQuery())
|
||||||
|
->setViewer($this->getViewer())
|
||||||
|
->withPHIDs(mpull($carts, 'getMerchantPHID'))
|
||||||
|
->execute();
|
||||||
|
$merchants = mpull($merchants, null, 'getPHID');
|
||||||
|
|
||||||
|
foreach ($carts as $key => $cart) {
|
||||||
|
$merchant = idx($merchants, $cart->getMerchantPHID());
|
||||||
|
if (!$merchant) {
|
||||||
|
unset($carts[$key]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$cart->attachMerchant($merchant);
|
||||||
|
}
|
||||||
|
|
||||||
$implementations = array();
|
$implementations = array();
|
||||||
|
|
||||||
$cart_map = mgroup($carts, 'getCartClass');
|
$cart_map = mgroup($carts, 'getCartClass');
|
||||||
|
|
|
@ -6,6 +6,7 @@ final class PhortunePaymentMethodQuery
|
||||||
private $ids;
|
private $ids;
|
||||||
private $phids;
|
private $phids;
|
||||||
private $accountPHIDs;
|
private $accountPHIDs;
|
||||||
|
private $merchantPHIDs;
|
||||||
private $statuses;
|
private $statuses;
|
||||||
|
|
||||||
public function withIDs(array $ids) {
|
public function withIDs(array $ids) {
|
||||||
|
@ -23,6 +24,11 @@ final class PhortunePaymentMethodQuery
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function withMerchantPHIDs(array $phids) {
|
||||||
|
$this->merchantPHIDs = $phids;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function withStatuses(array $statuses) {
|
public function withStatuses(array $statuses) {
|
||||||
$this->statuses = $statuses;
|
$this->statuses = $statuses;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -44,15 +50,6 @@ final class PhortunePaymentMethodQuery
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function willFilterPage(array $methods) {
|
protected function willFilterPage(array $methods) {
|
||||||
foreach ($methods as $key => $method) {
|
|
||||||
try {
|
|
||||||
$method->buildPaymentProvider();
|
|
||||||
} catch (Exception $ex) {
|
|
||||||
unset($methods[$key]);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$accounts = id(new PhortuneAccountQuery())
|
$accounts = id(new PhortuneAccountQuery())
|
||||||
->setViewer($this->getViewer())
|
->setViewer($this->getViewer())
|
||||||
->withPHIDs(mpull($methods, 'getAccountPHID'))
|
->withPHIDs(mpull($methods, 'getAccountPHID'))
|
||||||
|
@ -68,6 +65,36 @@ final class PhortunePaymentMethodQuery
|
||||||
$method->attachAccount($account);
|
$method->attachAccount($account);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$merchants = id(new PhortuneMerchantQuery())
|
||||||
|
->setViewer($this->getViewer())
|
||||||
|
->withPHIDs(mpull($methods, 'getMerchantPHID'))
|
||||||
|
->execute();
|
||||||
|
$merchants = mpull($merchants, null, 'getPHID');
|
||||||
|
|
||||||
|
foreach ($methods as $key => $method) {
|
||||||
|
$merchant = idx($merchants, $method->getMerchantPHID());
|
||||||
|
if (!$merchant) {
|
||||||
|
unset($methods[$key]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$method->attachMerchant($merchant);
|
||||||
|
}
|
||||||
|
|
||||||
|
$provider_configs = id(new PhortunePaymentProviderConfigQuery())
|
||||||
|
->setViewer($this->getViewer())
|
||||||
|
->withPHIDs(mpull($methods, 'getProviderPHID'))
|
||||||
|
->execute();
|
||||||
|
$provider_configs = mpull($provider_configs, null, 'getPHID');
|
||||||
|
|
||||||
|
foreach ($methods as $key => $method) {
|
||||||
|
$provider_config = idx($provider_configs, $method->getProviderPHID());
|
||||||
|
if (!$provider_config) {
|
||||||
|
unset($methods[$key]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$method->attachProviderConfig($provider_config);
|
||||||
|
}
|
||||||
|
|
||||||
return $methods;
|
return $methods;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,6 +122,13 @@ final class PhortunePaymentMethodQuery
|
||||||
$this->accountPHIDs);
|
$this->accountPHIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->merchantPHIDs !== null) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn,
|
||||||
|
'merchantPHID IN (%Ls)',
|
||||||
|
$this->merchantPHIDs);
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->statuses !== null) {
|
if ($this->statuses !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn,
|
$conn,
|
||||||
|
|
|
@ -58,9 +58,10 @@ final class PhortuneAccount extends PhortuneDAO
|
||||||
|
|
||||||
public function newCart(
|
public function newCart(
|
||||||
PhabricatorUser $actor,
|
PhabricatorUser $actor,
|
||||||
PhortuneCartImplementation $implementation) {
|
PhortuneCartImplementation $implementation,
|
||||||
|
PhortuneMerchant $merchant) {
|
||||||
|
|
||||||
$cart = PhortuneCart::initializeNewCart($actor, $this);
|
$cart = PhortuneCart::initializeNewCart($actor, $this, $merchant);
|
||||||
|
|
||||||
$cart->setCartClass(get_class($implementation));
|
$cart->setCartClass(get_class($implementation));
|
||||||
$cart->attachImplementation($implementation);
|
$cart->attachImplementation($implementation);
|
||||||
|
|
|
@ -11,6 +11,7 @@ final class PhortuneCart extends PhortuneDAO
|
||||||
|
|
||||||
protected $accountPHID;
|
protected $accountPHID;
|
||||||
protected $authorPHID;
|
protected $authorPHID;
|
||||||
|
protected $merchantPHID;
|
||||||
protected $cartClass;
|
protected $cartClass;
|
||||||
protected $status;
|
protected $status;
|
||||||
protected $metadata = array();
|
protected $metadata = array();
|
||||||
|
@ -18,14 +19,17 @@ final class PhortuneCart extends PhortuneDAO
|
||||||
private $account = self::ATTACHABLE;
|
private $account = self::ATTACHABLE;
|
||||||
private $purchases = self::ATTACHABLE;
|
private $purchases = self::ATTACHABLE;
|
||||||
private $implementation = self::ATTACHABLE;
|
private $implementation = self::ATTACHABLE;
|
||||||
|
private $merchant = self::ATTACHABLE;
|
||||||
|
|
||||||
public static function initializeNewCart(
|
public static function initializeNewCart(
|
||||||
PhabricatorUser $actor,
|
PhabricatorUser $actor,
|
||||||
PhortuneAccount $account) {
|
PhortuneAccount $account,
|
||||||
|
PhortuneMerchant $merchant) {
|
||||||
$cart = id(new PhortuneCart())
|
$cart = id(new PhortuneCart())
|
||||||
->setAuthorPHID($actor->getPHID())
|
->setAuthorPHID($actor->getPHID())
|
||||||
->setStatus(self::STATUS_BUILDING)
|
->setStatus(self::STATUS_BUILDING)
|
||||||
->setAccountPHID($account->getPHID());
|
->setAccountPHID($account->getPHID())
|
||||||
|
->setMerchantPHID($merchant->getPHID());
|
||||||
|
|
||||||
$cart->account = $account;
|
$cart->account = $account;
|
||||||
$cart->purchases = array();
|
$cart->purchases = array();
|
||||||
|
@ -63,7 +67,8 @@ final class PhortuneCart extends PhortuneDAO
|
||||||
->setAccountPHID($account->getPHID())
|
->setAccountPHID($account->getPHID())
|
||||||
->setCartPHID($this->getPHID())
|
->setCartPHID($this->getPHID())
|
||||||
->setAuthorPHID($actor->getPHID())
|
->setAuthorPHID($actor->getPHID())
|
||||||
->setPaymentProviderKey($provider->getProviderKey())
|
->setMerchantPHID($this->getMerchant()->getPHID())
|
||||||
|
->setProviderPHID($provider->getProviderConfig()->getPHID())
|
||||||
->setAmountAsCurrency($this->getTotalPriceAsCurrency());
|
->setAmountAsCurrency($this->getTotalPriceAsCurrency());
|
||||||
|
|
||||||
if ($method) {
|
if ($method) {
|
||||||
|
@ -154,6 +159,9 @@ final class PhortuneCart extends PhortuneDAO
|
||||||
'key_account' => array(
|
'key_account' => array(
|
||||||
'columns' => array('accountPHID'),
|
'columns' => array('accountPHID'),
|
||||||
),
|
),
|
||||||
|
'key_merchant' => array(
|
||||||
|
'columns' => array('merchantPHID'),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
) + parent::getConfiguration();
|
) + parent::getConfiguration();
|
||||||
}
|
}
|
||||||
|
@ -182,6 +190,15 @@ final class PhortuneCart extends PhortuneDAO
|
||||||
return $this->assertAttached($this->account);
|
return $this->assertAttached($this->account);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function attachMerchant(PhortuneMerchant $merchant) {
|
||||||
|
$this->merchant = $merchant;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMerchant() {
|
||||||
|
return $this->assertAttached($this->merchant);
|
||||||
|
}
|
||||||
|
|
||||||
public function attachImplementation(
|
public function attachImplementation(
|
||||||
PhortuneCartImplementation $implementation) {
|
PhortuneCartImplementation $implementation) {
|
||||||
$this->implementation = $implementation;
|
$this->implementation = $implementation;
|
||||||
|
|
|
@ -16,7 +16,8 @@ final class PhortuneCharge extends PhortuneDAO
|
||||||
protected $accountPHID;
|
protected $accountPHID;
|
||||||
protected $authorPHID;
|
protected $authorPHID;
|
||||||
protected $cartPHID;
|
protected $cartPHID;
|
||||||
protected $paymentProviderKey;
|
protected $providerPHID;
|
||||||
|
protected $merchantPHID;
|
||||||
protected $paymentMethodPHID;
|
protected $paymentMethodPHID;
|
||||||
protected $amountAsCurrency;
|
protected $amountAsCurrency;
|
||||||
protected $status;
|
protected $status;
|
||||||
|
@ -52,6 +53,12 @@ final class PhortuneCharge extends PhortuneDAO
|
||||||
'key_account' => array(
|
'key_account' => array(
|
||||||
'columns' => array('accountPHID'),
|
'columns' => array('accountPHID'),
|
||||||
),
|
),
|
||||||
|
'key_merchant' => array(
|
||||||
|
'columns' => array('merchantPHID'),
|
||||||
|
),
|
||||||
|
'key_provider' => array(
|
||||||
|
'columns' => array('providerPHID'),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
) + parent::getConfiguration();
|
) + parent::getConfiguration();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ final class PhortunePaymentMethod extends PhortuneDAO
|
||||||
protected $status;
|
protected $status;
|
||||||
protected $accountPHID;
|
protected $accountPHID;
|
||||||
protected $authorPHID;
|
protected $authorPHID;
|
||||||
|
protected $merchantPHID;
|
||||||
protected $providerPHID;
|
protected $providerPHID;
|
||||||
protected $expires;
|
protected $expires;
|
||||||
protected $metadata = array();
|
protected $metadata = array();
|
||||||
|
@ -21,6 +22,8 @@ final class PhortunePaymentMethod extends PhortuneDAO
|
||||||
protected $lastFourDigits;
|
protected $lastFourDigits;
|
||||||
|
|
||||||
private $account = self::ATTACHABLE;
|
private $account = self::ATTACHABLE;
|
||||||
|
private $merchant = self::ATTACHABLE;
|
||||||
|
private $providerConfig = self::ATTACHABLE;
|
||||||
|
|
||||||
public function getConfiguration() {
|
public function getConfiguration() {
|
||||||
return array(
|
return array(
|
||||||
|
@ -39,6 +42,9 @@ final class PhortunePaymentMethod extends PhortuneDAO
|
||||||
'key_account' => array(
|
'key_account' => array(
|
||||||
'columns' => array('accountPHID', 'status'),
|
'columns' => array('accountPHID', 'status'),
|
||||||
),
|
),
|
||||||
|
'key_merchant' => array(
|
||||||
|
'columns' => array('merchantPHID', 'accountPHID'),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
) + parent::getConfiguration();
|
) + parent::getConfiguration();
|
||||||
}
|
}
|
||||||
|
@ -57,6 +63,24 @@ final class PhortunePaymentMethod extends PhortuneDAO
|
||||||
return $this->assertAttached($this->account);
|
return $this->assertAttached($this->account);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function attachMerchant(PhortuneMerchant $merchant) {
|
||||||
|
$this->merchant = $merchant;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMerchant() {
|
||||||
|
return $this->assertAttached($this->merchant);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function attachProviderConfig(PhortunePaymentProviderConfig $config) {
|
||||||
|
$this->providerConfig = $config;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getProviderConfig() {
|
||||||
|
return $this->assertAttached($this->providerConfig);
|
||||||
|
}
|
||||||
|
|
||||||
public function getDescription() {
|
public function getDescription() {
|
||||||
$provider = $this->buildPaymentProvider();
|
$provider = $this->buildPaymentProvider();
|
||||||
return $provider->getPaymentMethodProviderDescription();
|
return $provider->getPaymentMethodProviderDescription();
|
||||||
|
@ -72,7 +96,7 @@ final class PhortunePaymentMethod extends PhortuneDAO
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildPaymentProvider() {
|
public function buildPaymentProvider() {
|
||||||
throw new Exception(pht('TODO: Reimplement this junk.'));
|
return $this->getProviderConfig()->buildProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDisplayName() {
|
public function getDisplayName() {
|
||||||
|
|
Loading…
Reference in a new issue