Exemplo n.º 1
0
 public function buildPaymentProvider()
 {
     $providers = PhortunePaymentProvider::getAllProviders();
     $accept = array();
     foreach ($providers as $provider) {
         if ($provider->canHandlePaymentMethod($this)) {
             $accept[] = $provider;
         }
     }
     if (!$accept) {
         throw new PhortuneNoPaymentProviderException($this);
     }
     if (count($accept) > 1) {
         throw new PhortuneMultiplePaymentProvidersException($this, $accept);
     }
     return head($accept);
 }
 private function processChooseClassRequest(AphrontRequest $request, PhortuneMerchant $merchant, array $current_map)
 {
     $viewer = $request->getUser();
     $providers = PhortunePaymentProvider::getAllProviders();
     $v_class = null;
     $errors = array();
     if ($request->isFormPost()) {
         $v_class = $request->getStr('class');
         if (!isset($providers[$v_class])) {
             $errors[] = pht('You must select a valid provider type.');
         }
     }
     $merchant_id = $merchant->getID();
     $cancel_uri = $this->getApplicationURI("merchant/{$merchant_id}/");
     if (!$v_class) {
         $v_class = key($providers);
     }
     $panel_classes = id(new AphrontFormRadioButtonControl())->setName('class')->setValue($v_class);
     $providers = msort($providers, 'getConfigureName');
     foreach ($providers as $class => $provider) {
         $disabled = isset($current_map[$class]);
         if ($disabled) {
             $description = phutil_tag('em', array(), pht('This merchant already has a payment account configured ' . 'with this provider.'));
         } else {
             $description = $provider->getConfigureDescription();
         }
         $panel_classes->addButton($class, $provider->getConfigureName(), $description, null, $disabled);
     }
     $form = id(new AphrontFormView())->setUser($viewer)->addHiddenInput('merchantID', $merchant->getID())->appendRemarkupInstructions(pht('Choose the type of payment provider to add:'))->appendChild($panel_classes)->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Continue'))->addCancelButton($cancel_uri));
     $title = pht('Add Payment Provider');
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb($merchant->getName(), $cancel_uri);
     $crumbs->addTextCrumb($title);
     $box = id(new PHUIObjectBoxView())->setHeaderText($title)->setFormErrors($errors)->setForm($form);
     return $this->buildApplicationPage(array($crumbs, $box), array('title' => $title));
 }
 public function testGetAllProviders()
 {
     PhortunePaymentProvider::getAllProviders();
     $this->assertTrue(true);
 }