コード例 #1
0
 protected function loadPage()
 {
     $table = new PhortunePaymentMethod();
     $conn = $table->establishConnection('r');
     $rows = queryfx_all($conn, 'SELECT * FROM %T %Q %Q %Q', $table->getTableName(), $this->buildWhereClause($conn), $this->buildOrderClause($conn), $this->buildLimitClause($conn));
     return $table->loadAllFromArray($rows);
 }
コード例 #2
0
 public function __construct(PhortunePaymentMethod $method, array $providers)
 {
     assert_instances_of($providers, 'PhortunePaymentProvider');
     $type = $method->getMetadataValue('type');
     $provider_names = array();
     foreach ($providers as $provider) {
         $provider_names[] = get_class($provider);
     }
     return parent::__construct("More than one payment provider can handle charging payments for this " . "payment method. This is ambiguous and likely indicates that a payment " . "provider is not properly implemented. You may be able to use a " . "different payment method to complete this transaction. The payment " . "method type is '{$type}'. The providers claiming to handle it are: " . implode(', ', $provider_names) . '.');
 }
コード例 #3
0
ファイル: PhortuneCart.php プロジェクト: rchicoli/phabricator
 public function willApplyCharge(PhabricatorUser $actor, PhortunePaymentProvider $provider, PhortunePaymentMethod $method = null)
 {
     $account = $this->getAccount();
     $charge = PhortuneCharge::initializeNewCharge()->setAccountPHID($account->getPHID())->setCartPHID($this->getPHID())->setAuthorPHID($actor->getPHID())->setMerchantPHID($this->getMerchant()->getPHID())->setProviderPHID($provider->getProviderConfig()->getPHID())->setAmountAsCurrency($this->getTotalPriceAsCurrency());
     if ($method) {
         $charge->setPaymentMethodPHID($method->getPHID());
     }
     $this->openTransaction();
     $this->beginReadLocking();
     $copy = clone $this;
     $copy->reload();
     if ($copy->getStatus() !== self::STATUS_READY) {
         throw new Exception(pht('Cart has wrong status ("%s") to call %s, expected "%s".', $copy->getStatus(), 'willApplyCharge()', self::STATUS_READY));
     }
     $charge->save();
     $this->setStatus(self::STATUS_PURCHASING)->save();
     $this->endReadLocking();
     $this->saveTransaction();
     return $charge;
 }
コード例 #4
0
 /**
  * @phutil-external-symbol class Stripe_Token
  * @phutil-external-symbol class Stripe_Customer
  */
 public function createPaymentMethodFromRequest(AphrontRequest $request, PhortunePaymentMethod $method, array $token)
 {
     $errors = array();
     $root = dirname(phutil_get_library_root('phabricator'));
     require_once $root . '/externals/stripe-php/lib/Stripe.php';
     $secret_key = $this->getSecretKey();
     $stripe_token = $token['stripeCardToken'];
     // First, make sure the token is valid.
     $info = id(new Stripe_Token())->retrieve($stripe_token, $secret_key);
     $account_phid = $method->getAccountPHID();
     $author_phid = $method->getAuthorPHID();
     $params = array('card' => $stripe_token, 'description' => $account_phid . ':' . $author_phid);
     // Then, we need to create a Customer in order to be able to charge
     // the card more than once. We create one Customer for each card;
     // they do not map to PhortuneAccounts because we allow an account to
     // have more than one active card.
     $customer = Stripe_Customer::create($params, $secret_key);
     $card = $info->card;
     $method->setBrand($card->brand)->setLastFourDigits($card->last4)->setExpires($card->exp_year, $card->exp_month)->setMetadata(array('type' => 'stripe.customer', 'stripe.customerID' => $customer->id, 'stripe.cardToken' => $stripe_token));
     return $errors;
 }
コード例 #5
0
 /**
  * @phutil-external-symbol class Balanced\Card
  * @phutil-external-symbol class Balanced\Settings
  * @phutil-external-symbol class Balanced\Marketplace
  * @phutil-external-symbol class RESTful\Exceptions\HTTPError
  */
 public function createPaymentMethodFromRequest(AphrontRequest $request, PhortunePaymentMethod $method, array $token)
 {
     $errors = array();
     $root = dirname(phutil_get_library_root('phabricator'));
     require_once $root . '/externals/httpful/bootstrap.php';
     require_once $root . '/externals/restful/bootstrap.php';
     require_once $root . '/externals/balanced-php/bootstrap.php';
     $account_phid = $method->getAccountPHID();
     $author_phid = $method->getAuthorPHID();
     $description = $account_phid . ':' . $author_phid;
     try {
         Balanced\Settings::$api_key = $this->getSecretKey();
         $card = Balanced\Card::get($token['balancedMarketplaceURI']);
         $buyer = Balanced\Marketplace::mine()->createBuyer(null, $card->uri, array('description' => $description));
     } catch (RESTful\Exceptions\HTTPError $error) {
         // NOTE: This exception doesn't print anything meaningful if it escapes
         // to top level. Replace it with something slightly readable.
         throw new Exception($error->response->body->description);
     }
     $method->setBrand($card->brand)->setLastFourDigits($card->last_four)->setExpires($card->expiration_year, $card->expiration_month)->setMetadata(array('type' => 'balanced.account', 'balanced.accountURI' => $buyer->uri, 'balanced.cardURI' => $card->uri));
     return $errors;
 }
コード例 #6
0
 public function canHandlePaymentMethod(PhortunePaymentMethod $method)
 {
     $type = $method->getMetadataValue('type');
     return $type === 'test.multiple';
 }
コード例 #7
0
 public function createPaymentMethodFromRequest(AphrontRequest $request, PhortunePaymentMethod $method, array $token)
 {
     $method->setExpires('2050', '01')->setBrand('FreeMoney')->setLastFourDigits('9999')->setMetadata(array('type' => 'test.wealth'));
     return array();
 }
コード例 #8
0
 public function __construct(PhortunePaymentMethod $method)
 {
     $type = $method->getMetadataValue('type');
     return parent::__construct("No available payment provider can handle charging payments for this " . "payment method. You may be able to use a different payment method to " . "complete this transaction. The payment method type is '{$type}'.");
 }
コード例 #9
0
 public function canHandlePaymentMethod(PhortunePaymentMethod $method)
 {
     $type = $method->getMetadataValue('type');
     return $type == 'paypal';
 }