/** * @phutil-external-symbol class Stripe_Charge */ protected function executeCharge(PhortunePaymentMethod $method, PhortuneCharge $charge) { $root = dirname(phutil_get_library_root('phabricator')); require_once $root . '/externals/stripe-php/lib/Stripe.php'; $secret_key = $this->getSecretKey(); $params = array('amount' => $charge->getAmountInCents(), 'currency' => 'usd', 'customer' => $method->getMetadataValue('stripe.customerID'), 'description' => $charge->getPHID(), 'capture' => true); $stripe_charge = Stripe_Charge::create($params, $secret_key); $id = $stripe_charge->id; if (!$id) { throw new Exception('Stripe charge call did not return an ID!'); } $charge->setMetadataValue('stripe.chargeID', $id); }
protected function executeRefund(PhortuneCharge $charge, PhortuneCharge $refund) { $transaction_id = $charge->getMetadataValue('paypal.transactionID'); if (!$transaction_id) { throw new Exception(pht('Charge has no transaction ID!')); } $refund_amount = $refund->getAmountAsCurrency()->negate(); $refund_currency = $refund_amount->getCurrency(); $refund_value = $refund_amount->formatBareValue(); $params = array('TRANSACTIONID' => $transaction_id, 'REFUNDTYPE' => 'Partial', 'AMT' => $refund_value, 'CURRENCYCODE' => $refund_currency); $result = $this->newPaypalAPICall()->setRawPayPalQuery('RefundTransaction', $params)->resolve(); $charge->setMetadataValue('paypal.refundID', $result['REFUNDTRANSACTIONID']); }
protected function executeRefund(PhortuneCharge $charge, PhortuneCharge $refund) { $this->loadStripeAPILibraries(); $charge_id = $charge->getMetadataValue('stripe.chargeID'); if (!$charge_id) { throw new Exception(pht('Unable to refund charge; no Stripe chargeID!')); } $refund_cents = $refund->getAmountAsCurrency()->negate()->getValueInUSDCents(); $secret_key = $this->getSecretKey(); $params = array('amount' => $refund_cents); $stripe_charge = Stripe_Charge::retrieve($charge_id, $secret_key); $stripe_refund = $stripe_charge->refunds->create($params); $id = $stripe_refund->id; if (!$id) { throw new Exception(pht('Stripe refund call did not return an ID!')); } $charge->setMetadataValue('stripe.refundID', $id); $charge->save(); }