/**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     Stripe::setApiKey(\Config::get('stripe.key'));
     $accountId = $request->input('accountId');
     try {
         $stripeAccount = StripeAccount::retrieve($accountId);
         $stripeToken = self::getStripeToken();
         $stripeAccount->external_accounts->create(["external_account" => $stripeToken]);
     } catch (StripeError\Base $e) {
         return $e->getMessage();
     }
 }
示例#2
0
 public function addBankAccount(UserInterface $user, $dto)
 {
     $account = $this->em->getRepository(Account::getEntityClassByUser($user))->findOneBy(['user' => $user]);
     if (!$account) {
         $account = $this->createAccount($user);
     }
     $sa = \Stripe\Account::retrieve($account->getStripeId());
     $sa->bank_account = $dto->source;
     $sa->email = $user->getEmail();
     $sa->default_currency = $dto->currency;
     $sa->legal_entity->type = $dto->type;
     $sa->legal_entity->first_name = $dto->first_name;
     $sa->legal_entity->last_name = $dto->last_name;
     $sa->legal_entity->ssn_last_4 = $dto->ssn_last_4;
     $sa->legal_entity->business_name = $dto->business_name;
     $sa->legal_entity->address = ['line1' => $dto->address_line1, 'line2' => $dto->address_line2 ?: null, 'city' => $dto->city, 'state' => $dto->state, 'postal_code' => $dto->postal_code, 'country' => $dto->country];
     $sa->save();
     $account->updateBankAccounts($this->getBankAccounts($account)->data);
     $this->em->flush($account);
 }
 public function construct_form()
 {
     \Stripe\Stripe::setApiKey($this->stripe_private_key);
     $stripe_account = \Stripe\Account::retrieve();
     $default_currency_symbol = \Symfony\Component\Intl\Intl::getCurrencyBundle()->getCurrencySymbol(strtoupper($stripe_account->default_currency));
     $plans = \Stripe\Plan::all(array("limit" => 10));
     if (empty($this->formTemplate) || !file_exists($this->formTemplate)) {
         $this->set_form_template('');
     }
     $wp_nonce_field = wp_nonce_field($this->nonce_id, '_wpnonce', true, false);
     $donate['defaults']['currency'] = $stripe_account->default_currency;
     $currencies = $stripe_account->currencies_supported;
     $index = array_search($stripe_account->default_currency, $currencies);
     array_splice($currencies, $index, 1);
     array_unshift($currencies, $stripe_account->default_currency);
     ob_start();
     include $this->formTemplate;
     $return = ob_get_contents();
     ob_end_clean();
     return $return;
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($accountId = '')
 {
     Stripe::setApiKey(\Config::get('stripe.key'));
     try {
         $account = StripeAccount::retrieve($accountId);
         $result = $account->delete();
     } catch (Stripe\Error\Base $e) {
         echo $e->getMessage();
     }
     return redirect('/accounts');
 }
 /**
  * Handler for the gf_validate_secret_key AJAX request.
  */
 public function ajax_validate_secret_key()
 {
     // Get the API key name.
     $key_name = rgpost('keyName');
     // If no cache or if new value provided, do a fresh validation.
     $this->include_stripe_api();
     \Stripe\Stripe::setApiKey(rgpost('key'));
     // Initialize validatity state.
     $is_valid = true;
     try {
         // Attempt to retrieve account details.
         \Stripe\Account::retrieve();
     } catch (\Stripe\Error\Authentication $e) {
         // Set validity state to false.
         $is_valid = false;
         // Log that key validation failed.
         $this->log_error(__METHOD__ . "(): {$key_name}: " . $e->getMessage());
     }
     // Prepare response.
     $response = $is_valid ? 'valid' : 'invalid';
     // Send API key validation response.
     die($response);
 }
 public function temp($accountId, $cardId)
 {
     Stripe::setApiKey(\Config::get('stripe.key'));
     try {
         $account = StripeAccount::retrieve($accountId);
         $card = $account->external_accounts->retrieve($cardId);
         $stripeCustomer = StripeCustomer::create(["email" => '*****@*****.**', "description" => "Customer for test@example.com", "source" => self::getStripeToken()]);
         echo 'customerID = ' . $stripeCustomer->id;
         /*$stripeToken = StripeToken::create($card);
           echo 'token = '.$stripeToken.'<br>';*/
         /*$stripeToken = StripeToken::create([
               "card" => [
                   "number" => "5200828282828210",
                   "exp_month" => 8,
                   "exp_year" => 2018,
                   "cvc" => "314",
                   "currency" => "usd"
               ]
           ]);
           echo 'token = '.$stripeToken.'<br>';*/
         StripeCharge::create(array("amount" => 400, "currency" => "usd", "customer" => $stripeCustomer->id, "source" => '', "description" => "Charge for test@example.com"));
         return view('accounts.cards.show', ['card' => $card]);
     } catch (StripeError\Base $e) {
         return $e->getMessage();
     }
 }