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

Give Stripe complete payment workflow logic in Phortune

Summary:
Ref T2787. This basically already works correctly since the hard logic is external to the provider on API providers. Tweak a couple of things.

Failures still just fail the cart completely, for now.

Test Plan: Completed a charge with Stripe.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T2787

Differential Revision: https://secure.phabricator.com/D10640
This commit is contained in:
epriestley 2014-10-06 14:21:11 -07:00
parent 4ef547f8d6
commit 83e1a1ddb2
2 changed files with 13 additions and 4 deletions

View file

@ -39,6 +39,7 @@ final class PhortuneStripePaymentProvider extends PhortunePaymentProvider {
/**
* @phutil-external-symbol class Stripe_Charge
* @phutil-external-symbol class Stripe_CardError
*/
protected function executeCharge(
PhortunePaymentMethod $method,
@ -58,13 +59,20 @@ final class PhortuneStripePaymentProvider extends PhortunePaymentProvider {
'capture' => true,
);
$stripe_charge = Stripe_Charge::create($params, $secret_key);
try {
$stripe_charge = Stripe_Charge::create($params, $secret_key);
} catch (Stripe_CardError $ex) {
// TODO: Fail charge explicitly.
throw $ex;
}
$id = $stripe_charge->id;
if (!$id) {
throw new Exception('Stripe charge call did not return an ID!');
}
$charge->setMetadataValue('stripe.chargeID', $id);
$charge->save();
}
private function getPublishableKey() {

View file

@ -163,14 +163,15 @@ final class PhortuneWePayPaymentProvider extends PhortunePaymentProvider {
'funding_sources' => 'bank,cc'
);
$cart->willApplyCharge($viewer, $this);
$charge = $cart->willApplyCharge($viewer, $this);
$result = $wepay->request('checkout/create', $params);
$cart->setMetadataValue('provider.checkoutURI', $result->checkout_uri);
$cart->setMetadataValue('wepay.checkoutID', $result->checkout_id);
$cart->save();
$charge->setMetadataValue('wepay.checkoutID', $result->checkout_id);
$charge->save();
$uri = new PhutilURI($result->checkout_uri);
return id(new AphrontRedirectResponse())
->setIsExternal(true)