diff --git a/src/applications/phortune/provider/PhortuneStripePaymentProvider.php b/src/applications/phortune/provider/PhortuneStripePaymentProvider.php --- a/src/applications/phortune/provider/PhortuneStripePaymentProvider.php +++ b/src/applications/phortune/provider/PhortuneStripePaymentProvider.php @@ -39,6 +39,7 @@ /** * @phutil-external-symbol class Stripe_Charge + * @phutil-external-symbol class Stripe_CardError */ protected function executeCharge( PhortunePaymentMethod $method, @@ -58,13 +59,20 @@ '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() { diff --git a/src/applications/phortune/provider/PhortuneWePayPaymentProvider.php b/src/applications/phortune/provider/PhortuneWePayPaymentProvider.php --- a/src/applications/phortune/provider/PhortuneWePayPaymentProvider.php +++ b/src/applications/phortune/provider/PhortuneWePayPaymentProvider.php @@ -163,14 +163,15 @@ '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)