mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 22:10:55 +01:00
Smooth out Phortune purchase completion flow
Summary: Ref T2787. Currently, we dump the user back into the application. Instead, give them a confirmation screen and then let them continue. Also fix a couple of unit tests I adjusted the underlying behavior of somewhat-recently in libphutil. Test Plan: {F215498} Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T2787 Differential Revision: https://secure.phabricator.com/D10672
This commit is contained in:
parent
f41ae2228a
commit
f53861aa9d
9 changed files with 58 additions and 21 deletions
|
@ -81,4 +81,8 @@ final class FundBackerCart extends PhortuneCartImplementation {
|
|||
return '/'.$this->getInitiative()->getMonogram();
|
||||
}
|
||||
|
||||
public function getDoneActionName(PhortuneCart $cart) {
|
||||
return pht('Return to Initiative');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,10 @@ abstract class PhortuneCartImplementation {
|
|||
abstract public function getCancelURI(PhortuneCart $cart);
|
||||
abstract public function getDoneURI(PhortuneCart $cart);
|
||||
|
||||
public function getDoneActionName(PhortuneCart $cart) {
|
||||
return pht('Return to Application');
|
||||
}
|
||||
|
||||
public function assertCanCancelOrder(PhortuneCart $cart) {
|
||||
switch ($cart->getStatus()) {
|
||||
case PhortuneCart::STATUS_PURCHASED:
|
||||
|
|
|
@ -102,7 +102,7 @@ final class PhortuneCartCheckoutController
|
|||
|
||||
$cart->didApplyCharge($charge);
|
||||
|
||||
$done_uri = $cart->getDoneURI();
|
||||
$done_uri = $cart->getCheckoutURI();
|
||||
return id(new AphrontRedirectResponse())->setURI($done_uri);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ final class PhortuneCartViewController
|
|||
PhabricatorPolicyCapability::CAN_EDIT);
|
||||
|
||||
$errors = array();
|
||||
$error_view = null;
|
||||
$resume_uri = null;
|
||||
switch ($cart->getStatus()) {
|
||||
case PhortuneCart::STATUS_PURCHASING:
|
||||
|
@ -71,6 +72,12 @@ final class PhortuneCartViewController
|
|||
phutil_tag('strong', array(), pht('Update Status')));
|
||||
}
|
||||
break;
|
||||
case PhortuneCart::STATUS_PURCHASED:
|
||||
$error_view = id(new AphrontErrorView())
|
||||
->setSeverity(AphrontErrorView::SEVERITY_NOTICE)
|
||||
->appendChild(pht('This purchase has been completed.'));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$properties = $this->buildPropertyListView($cart);
|
||||
|
@ -85,12 +92,30 @@ final class PhortuneCartViewController
|
|||
->setUser($viewer)
|
||||
->setHeader(pht('Order Detail'));
|
||||
|
||||
if ($cart->getStatus() == PhortuneCart::STATUS_PURCHASED) {
|
||||
$done_uri = $cart->getDoneURI();
|
||||
if ($done_uri) {
|
||||
$header->addActionLink(
|
||||
id(new PHUIButtonView())
|
||||
->setTag('a')
|
||||
->setHref($done_uri)
|
||||
->setIcon(id(new PHUIIconView())
|
||||
->setIconFont('fa-check-square green'))
|
||||
->setText($cart->getDoneActionName()));
|
||||
}
|
||||
}
|
||||
|
||||
$cart_box = id(new PHUIObjectBoxView())
|
||||
->setHeader($header)
|
||||
->setFormErrors($errors)
|
||||
->appendChild($properties)
|
||||
->appendChild($cart_table);
|
||||
|
||||
if ($errors) {
|
||||
$cart_box->setFormErrors($errors);
|
||||
} else if ($error_view) {
|
||||
$cart_box->setErrorView($error_view);
|
||||
}
|
||||
|
||||
$charges = id(new PhortuneChargeQuery())
|
||||
->setViewer($viewer)
|
||||
->withCartPHIDs(array($cart->getPHID()))
|
||||
|
|
|
@ -450,7 +450,7 @@ final class PhortunePayPalPaymentProvider extends PhortunePaymentProvider {
|
|||
if ($success) {
|
||||
$cart->didApplyCharge($charge);
|
||||
$response = id(new AphrontRedirectResponse())->setURI(
|
||||
$cart->getDoneURI());
|
||||
$cart->getCheckoutURI());
|
||||
} else if ($hold) {
|
||||
$cart->didHoldCharge($charge);
|
||||
|
||||
|
|
|
@ -349,7 +349,7 @@ final class PhortuneWePayPaymentProvider extends PhortunePaymentProvider {
|
|||
$cart->didApplyCharge($charge);
|
||||
|
||||
$response = id(new AphrontRedirectResponse())->setURI(
|
||||
$cart->getDoneURI());
|
||||
$cart->getCheckoutURI());
|
||||
break;
|
||||
default:
|
||||
// It's not clear if we can ever get here on the web workflow,
|
||||
|
|
|
@ -332,6 +332,10 @@ final class PhortuneCart extends PhortuneDAO
|
|||
return $this->getImplementation()->getDoneURI($this);
|
||||
}
|
||||
|
||||
public function getDoneActionName() {
|
||||
return $this->getImplementation()->getDoneActionName($this);
|
||||
}
|
||||
|
||||
public function getCancelURI() {
|
||||
return $this->getImplementation()->getCancelURI($this);
|
||||
}
|
||||
|
|
|
@ -7,13 +7,13 @@ final class PhabricatorUnitsTestCase extends PhabricatorTestCase {
|
|||
|
||||
public function testByteFormatting() {
|
||||
$tests = array(
|
||||
1 => '1 B',
|
||||
1000 => '1 KB',
|
||||
1000000 => '1 MB',
|
||||
10000000 => '10 MB',
|
||||
100000000 => '100 MB',
|
||||
1000000000 => '1 GB',
|
||||
999 => '999 B',
|
||||
1 => '1 B',
|
||||
1024 => '1 KB',
|
||||
1024 * 1024 => '1 MB',
|
||||
10 * 1024 * 1024 => '10 MB',
|
||||
100 * 1024 * 1024 => '100 MB',
|
||||
1024 * 1024 * 1024 => '1 GB',
|
||||
999 => '999 B',
|
||||
);
|
||||
|
||||
foreach ($tests as $input => $expect) {
|
||||
|
@ -27,16 +27,16 @@ final class PhabricatorUnitsTestCase extends PhabricatorTestCase {
|
|||
public function testByteParsing() {
|
||||
$tests = array(
|
||||
'1' => 1,
|
||||
'1k' => 1000,
|
||||
'1K' => 1000,
|
||||
'1kB' => 1000,
|
||||
'1Kb' => 1000,
|
||||
'1KB' => 1000,
|
||||
'1MB' => 1000000,
|
||||
'1GB' => 1000000000,
|
||||
'1.5M' => 1500000,
|
||||
'1k' => 1024,
|
||||
'1K' => 1024,
|
||||
'1kB' => 1024,
|
||||
'1Kb' => 1024,
|
||||
'1KB' => 1024,
|
||||
'1MB' => 1024 * 1024,
|
||||
'1GB' => 1024 * 1024 * 1024,
|
||||
'1.5M' => (int)(1024 * 1024 * 1.5),
|
||||
'1 000' => 1000,
|
||||
'1,234.56 KB' => 1234560,
|
||||
'1,234.56 KB' => (int)(1024 * 1234.56),
|
||||
);
|
||||
|
||||
foreach ($tests as $input => $expect) {
|
||||
|
|
|
@ -85,7 +85,7 @@ final class PHUIObjectBoxView extends AphrontView {
|
|||
}
|
||||
|
||||
public function setFormErrors(array $errors, $title = null) {
|
||||
if (nonempty($errors)) {
|
||||
if ($errors) {
|
||||
$this->formErrors = id(new AphrontErrorView())
|
||||
->setTitle($title)
|
||||
->setErrors($errors);
|
||||
|
|
Loading…
Reference in a new issue