<?php

require_once './config/config.php';
// initialize a new generic provider
$provider = new \League\OAuth2\Client\Provider\GenericProvider(['clientId' => CLIENT_ID, 'clientSecret' => SECRET_KEY, 'redirectUri' => REDIRECT_URL, 'urlAuthorize' => 'https://connect.stripe.com/oauth/authorize', 'urlAccessToken' => 'https://connect.stripe.com/oauth/token', 'urlResourceOwnerDetails' => 'https://api.stripe.com/v1/account']);
// Check for an authorization code
if (isset($_GET['code'])) {
    $code = $_GET['code'];
    // Try to retrieve the access token
    try {
        $accessToken = $provider->getAccessToken('authorization_code', ['code' => $_GET['code']]);
        // You could retrieve the API key with `$accessToken->getToken()`, but it's better to authenticate using the Stripe-account header (below)
        // Retrieve the account ID to be used for authentication: https://stripe.com/docs/connect/authentication
        // TODO: Save this account ID to your database for later use.
        $account_id = $provider->getResourceOwner($accessToken)->getId();
        // Retrieve the account from Stripe: https://stripe.com/docs/api/php#retrieve_account
        $account = \Stripe\Account::Retrieve($account_id);
        $success = "Your Stripe account has been connected!";
    } catch (Exception $e) {
        $error = $e->getMessage();
    }
} elseif (isset($_GET['error'])) {
    $error = $_GET['error_description'];
} else {
    $error = "No authorization code received";
}
Exemplo n.º 2
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     \Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
     $account = \Stripe\Account::create(array("managed" => true, "country" => "US", "email" => $data['email'], "legal_entity" => ["dob" => ["day" => $data['dob_day'], "month" => $data['dob_month'], "year" => $data['dob_year']], "first_name" => $data['first_name'], "last_name" => $data['last_name'], "type" => "individual", "ssn_last_4" => $data['last_4'], "address" => ["city" => $data['address_city'], "country" => "US", "line1" => $data['address_line1'], "line2" => $data['address_line2'], "postal_code" => $data['address_zip'], "state" => $data['address_state']]], "tos_acceptance" => ["date" => time(), "ip" => $_SERVER['REMOTE_ADDR']], "external_account" => $data['stripe_token']));
     $user = User::create(['name' => $data['first_name'] . ' ' . $data['last_name'], 'email' => $data['email'], 'password' => bcrypt($data['password']), 'api_token' => str_random(60), 'slug' => str_random(10)]);
     $stripeAccount = \App\StripeAccount::Create(['user_id' => $user->id, 'stripe_id' => $account->id]);
     return $user;
 }
 /**
  * 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();
     }
 }
Exemplo n.º 4
0
 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');
 }
Exemplo n.º 6
0
 private function createAccount(UserInterface $user)
 {
     $entityClass = Account::getEntityClassByUser($user);
     /* @var $account AccountInterface */
     $account = new $entityClass();
     $account->setUser($user);
     $response = \Stripe\Account::create(['managed' => true, 'metadata' => ['id' => $user->getId(), 'type' => $user->getType()], 'email' => $user->getEmail()]);
     $account->setStripeId($response->id)->setSecretKey($response->keys->secret)->setPublishableKey($response->keys->publishable);
     $this->em->persist($account);
     $this->em->flush($account);
     return $account;
 }
Exemplo n.º 7
0
 function providerSignupAction()
 {
     if ($this->request->isPost()) {
         $name = $this->request->getPost('name');
         $email = $this->request->getPost('email');
         $password = $this->request->getPost('password');
         $cpassword = $this->request->getPost('cpassword');
         $timezone = $this->request->getPost('timezone');
         $phone = $this->request->getPost('phone');
         $address = $this->request->getPost('address');
         $categories = $this->request->getPost('categories');
         $membership = $this->request->getPost('membership');
         $card_token = $this->request->getPost('card_token');
         $errors = array();
         $fields = array('name', 'email', 'password', 'cpassword', 'phone', 'address', 'membership', 'card_token');
         $fieldsEntered = 0;
         foreach ($fields as $field) {
             if (trim(${$field}) != '') {
                 $fieldsEntered++;
             }
         }
         if ($fieldsEntered < count($fields)) {
             array_push($errors, "Some fields were not entered.");
         }
         if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
             array_push($errors, "Email is invalid.");
         }
         if (strlen($password) < 6) {
             array_push($errors, "Password must be at least 6 characters long.");
         }
         if ($password != $cpassword) {
             array_push($errors, "Passwords don't match.");
         }
         if (!preg_match('/^\\(?[0-9]{3}\\)?|[0-9]{3}[-. ]? [0-9]{3}[-. ]?[0-9]{4}$/', $phone)) {
             array_push($errors, "Invalid phone number format.");
         }
         $apiLink = $this->config->maps->api_link;
         $geoData = file_get_contents($apiLink . urlencode($address));
         if ($geoData === FALSE) {
             array_push($errors, "Invalid address.");
         }
         $provider = Providers::findFirst("email = '{$email}'");
         if ($provider) {
             array_push($errors, "Email is already taken.");
         }
         if (!count($errors)) {
             $salt = bin2hex(openssl_random_pseudo_bytes(16, $cstrong));
             $provider = new Providers();
             $provider->name = $name;
             $provider->email = $email;
             $provider->salt = $salt;
             $provider->password = md5($salt . $password);
             $provider->timezone = $timezone;
             $provider->membership = $membership;
             require_once "../vendor/stripe-php-master/init.php";
             \Stripe\Stripe::setApiKey($this->config->stripe->secret_key);
             $plan = Memberships::findFirst("id = '{$membership}'");
             $amount = (int) $plan->total * 100;
             $duration = $plan->duration;
             $date = new DateTime(date());
             $date->add(new DateInterval('P' . $duration . 'M'));
             $provider->expiry_date = $date->format('Y-m-d H:i:s');
             $account = \Stripe\Account::create(array("managed" => true, "country" => "US"));
             $provider->stripe_account_token = $account->id;
             $customer = \Stripe\Customer::create(array("description" => $name, "email" => $email, "source" => $card_token));
             $provider->stripe_customer_token = $customer->id;
             $provider->stripe_card_token = $customer->default_source;
             $providerPhone = new ProviderPhones();
             $providerPhone->telephone = $phone;
             $provider->providerPhones = $providerPhone;
             $providerAddress = new ProviderAddresses();
             $geoJSON = json_decode($geoData);
             if ($geoJSON->status == "OK") {
                 $geometry = $geoJSON->results[0]->geometry->location;
                 $lat = $geometry->lat;
                 $lng = $geometry->lng;
             } else {
                 $lat = 0;
                 $lng = 0;
             }
             $providerAddress->latitude = $lat;
             $providerAddress->longitude = $lng;
             $providerAddress->address = $address;
             $provider->providerAddresses = $providerAddress;
             $providerCategories = array();
             foreach ($categories as $category) {
                 $providerCategory = new ProviderCategories();
                 $providerCategory->cid = $category;
                 array_push($providerCategories, $providerCategory);
             }
             $provider->providerCategories = $providerCategories;
             if ($provider->create()) {
                 \Stripe\Charge::create(array("amount" => $amount, "currency" => "usd", "customer" => $provider->stripe_customer_token, "source" => $provider->stripe_card_token, "description" => "{$plan->name} plan subscription"));
                 $this->response->redirect('/login?success');
                 $this->view->disable();
             } else {
                 array_push($errors, "An error occurred during the signup process.");
             }
         }
         $this->view->errors = $errors;
     }
     $timezones = (require "../app/config/timezones.php");
     $this->view->timezones = $timezones;
     $memberships = Memberships::find("id > 1");
     $this->view->memberships = $memberships;
     $categories = Categories::find();
     $this->view->categories = $categories;
     echo $this->view->render('auth', 'providerSignup');
 }
 /**
  * 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();
     }
 }