if (!empty($params['stg_currency'])) {
     $row['currency'] = $params['stg_currency'];
 }
 if (!empty($params['stg_surrate'])) {
     $row['surchargerate'] = $params['stg_surrate'];
 }
 $symbol = StripeGate\Utils::GetSymbol($row['currency']);
 $amount = StripeGate\Utils::GetPrivateAmount($params['stg_amount'], $row['amountformat'], $symbol);
 if ($row['surchargerate'] > 0.0 && empty($params['sgt_nosur'])) {
     $amount = ceil($amount * (1.0 + $row['surchargerate']));
 }
 $card = array('number' => $params['stg_number'], 'exp_month' => $params['stg_month'], 'exp_year' => $params['stg_year'], 'cvc' => $params['stg_cvc']);
 $exdata = array('paywhat' => $params['stg_paywhat'], 'payfor' => $params['stg_payfor']);
 $data = array('amount' => $amount, 'currency' => $row['currency'], 'source' => $card, 'metadata' => $exdata);
 try {
     Stripe\Stripe::setApiKey($privkey);
     $charge = Stripe\Charge::create($data);
     //synchronous
     $params = array_merge($params, $charge->__toArray(TRUE));
     $caller = NULL;
     $funcs = new StripeGate\Payer($caller, $this);
     $funcs->HandleResult($params);
     //redirects
     exit;
 } catch (Exception $e) {
     $message = $e->getMessage();
     //all inputs resume
     foreach ($params as $key => $val) {
         if (strpos($key, 'stg_') === 0) {
             $t = substr($key, 4);
             ${$t} = $val;
 if ($payment == '1') {
     $amount = 7;
 }
 if (isset($token)) {
     if ($token == ($stripeToken['token'] = $app['session']->get('stripeToken'))) {
         $errors['token'] = 'You have apparently re-submitted the form.';
     } else {
         $app['session']->set('stripeToken', array('token' => $token));
     }
 } else {
     $errors['token'] = 'The order cannot be processed. You have not been charged.
                 Please confirm that you have JavaScript enabled and try again.';
 }
 if (empty($errors)) {
     try {
         Stripe\Stripe::setApiKey($privateKey);
         //                    $uspsUrl = "http://production.shippingapis.com/ShippingApi.dll";
         //                    $res = curl_init();
         //
         ////                    Set the Target URL
         //                    curl_setopt($res, CURLOPT_URL, $uspsUrl);
         //                    curl_setopt($res, CURLOPT_HEADER, 1);
         //                    curl_setopt($res, CURLOPT_RETURNTRANSFER, 1);
         //
         ////                    parameters to post
         //                    curl_setopt($res, CURLOPT_POST, 1);
         //
         //                    $uspsData = "API=RateV4&XML=
         //                    <RateV4Request USERID=\"$uspsUsername\">
         //                        <Package ID=\"1ST\">
         //                            <Service>PRIORITY</Service>
 public function doConnect()
 {
     // Validation
     $rules = array('stripe' => 'min:16|max:64|required');
     // run the validation rules on the inputs
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         // validation error -> sending back
         $failedAttribute = $validator->invalid();
         return Redirect::back()->with('error', $validator->errors()->get(key($failedAttribute))[0])->withInput();
         // sending back data
     } else {
         // validator success
         try {
             // trying to login with this key
             Stripe\Stripe::setApiKey(Input::get('stripe'));
             $account = Stripe\Account::retrieve();
             // catchable line
             // success
             $returned_object = json_decode(strstr($account, '{'), true);
             // updating the user
             $user = Auth::user();
             $user->ready = 'connecting';
             // setting key
             $user->stripe_key = Input::get('stripe');
             // setting name if is null
             if (strlen($user->name) == 0) {
                 $user->name = $returned_object['display_name'];
             }
             if (strlen($user->zoneinfo) == 0) {
                 $user->zoneinfo = $returned_object['country'];
             }
             // saving user
             $user->save();
             IntercomHelper::connected($user, 'stripe');
             Queue::push('CalculateFirstTime', array('userID' => $user->id));
         } catch (Stripe\Error\Authentication $e) {
             // code was invalid
             return Redirect::back()->with('error', "Authentication unsuccessful!");
         }
         // redirect to get stripe
         return Redirect::route('auth.dashboard')->with(array('success' => 'Stripe connected.'));
     }
 }
Exemple #4
0
<?php

require 'stripe-php-2.2.0/init.php';
if ($_POST) {
    Stripe\Stripe::setApiKey("sk_test_UYrpaLslRJJDQd0Wk3sDFePZ");
    $error = '';
    $success = '';
    try {
        if (!isset($_POST['stripeToken'])) {
            throw new Exception("The Stripe Token was not generated correctly");
        }
        Stripe\Charge::create(array("amount" => $_POST['amount'], "currency" => "cad", "card" => $_POST['stripeToken']));
        $success = 'Your payment was successful.';
        header("Location: ../public_html/success.php");
        die;
    } catch (\Stripe\Error\Card $e) {
        $error = $e->getMessage();
    }
}
 /**
  * Getting Apikey from Stripe Payment
  */
 public function __construct()
 {
     Stripe\Stripe::setApiKey($this->getConfigData('api_key'));
 }
    $code = $_GET['code'];
    $url = 'https://connect.stripe.com/oauth/token';
    $data = array('client_secret' => 'sk_test_gzpJWMGs2ClZowZ4rzEO0PW5', 'grant_type' => 'authorization_code', 'client_id' => 'ca_6hSzuFypAh5oMFgXnHOvWhLu7L10qexb', 'code' => $code);
    $options = array('http' => array('header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($data)));
    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    $resp = json_decode($result);
    if (isset($resp->stripe_user_id)) {
        $stripe_user_id = $resp->stripe_user_id;
        $query1 = "SELECT * FROM website_users_to_sellers WHERE stripe_user_id = '{$stripe_user_id}' AND user_unid = '{$user_unid}'";
        $result1 = mysql_query($query1);
        if (!$result1) {
            die('Invalid query: ' . mysql_error());
        }
        if (mysql_num_rows($result1) == 0) {
            Stripe\Stripe::setApiKey($resp->access_token);
            $seller_account = Stripe\Account::retrieve($stripe_user_id);
            $seller_insert = array('stripe_user_id' => $resp->stripe_user_id, 'access_token' => $resp->access_token, 'stripe_publishable_key' => $resp->stripe_publishable_key, 'refresh_token' => $resp->refresh_token, 'created_user_unid' => $user_unid, 'address_line2' => $seller_account->legal_entity[0]->address->line1, 'address_line2' => $seller_account->legal_entity[0]->address->line2, 'address_city' => $seller_account->legal_entity[0]->address->city, 'address_state' => $seller_account->legal_entity[0]->address->state, 'address_poastal_code' => $seller_account->legal_entity[0]->address->postal_code, 'business_url' => $seller_account->business_url, 'account_email' => $seller_account->email, 'business_name' => $seller_account->business_name, 'display_name' => $seller_account->display_name, 'timezone' => $seller_account->timezone, 'first_name' => $seller_account->legal_entity[1]->first_name, 'last_name' => $seller_account->legal_entity[1]->last_name, 'type' => $seller_account->legal_entity[0]->type);
            $seller_unid = db_insert_array($seller_insert, 'website_seller_account');
            $user_to_account = array('seller_unid' => $seller_unid, 'user_unid' => $user_unid, 'stripe_user_id' => $stripe_user_id, 'type' => $seller_account->legal_entity[0]->type);
            $do_script = db_insert_array($user_to_account, 'website_users_to_sellers');
            //header("Location: /seller-accounts.php");
        }
        // no duplicate accounts
        $url_error = urlencode('Duplicate Stripe/Seller Account');
        header("Location: /seller-accounts.php?error={$url_error}");
    }
    // isset sctripe account
} else {
    if (isset($_GET['error'])) {
        // Error
Exemple #7
0
<?php

$filename = __DIR__ . preg_replace('#(\\?.*)$#', '', $_SERVER['REQUEST_URI']);
if (php_sapi_name() === 'cli-server' && is_file($filename)) {
    return false;
}
include __DIR__ . "/../vendor/autoload.php";
if (file_exists(__DIR__ . "/../.env")) {
    $dotenv = new Dotenv\Dotenv(__DIR__ . "/../");
    $dotenv->overload();
}
$app = new Silex\Application();
$app['debug'] = true;
$app['password'] = json_decode(getenv('USER_PASSWORD'));
$app['adminPassword'] = getenv('ADMIN_PASSWORD');
$app['isAdmin'] = false;
Stripe\Stripe::setApiKey(getenv("STRIPE_SECRET"));
$app->register(new MH\Provider\ControllerProvider());
$app->register(new MH\Provider\DomainProvider());
$app->register(new MH\Provider\MiddlewareProvider());
$app->register(new MH\Provider\VendorProvider());
$app->mount('/', new MH\Provider\RouteProvider());
$app->run();
<?php

require_once 'constants.php';
if (!empty($_POST)) {
    require_once 'stripe-php/init.php';
    require_once 'PHPMailer/PHPMailerAutoload.php';
    Stripe\Stripe::setApiKey(STRIPE_SECRET_KEY);
    //<- stripe secret key. Find out about environment variables.
    // Get the credit card details submitted by the form
    $token = $_POST['stripeToken'];
    $name = $_POST["firstName"] . " " . $_POST["lastName"];
    $email = $_POST["email"];
    $address = $_POST["address"];
    $address2 = $_POST["address2"];
    $city = $_POST["city"];
    $state = $_POST["state"];
    $zip = $_POST["zip"];
    $amount = $_POST["amount"];
    // Create the charge on Stripe's servers - this will charge the user's card
    try {
        $charge = \Stripe\Charge::create(array("amount" => intval($amount), "currency" => "usd", "source" => $token, "description" => "Donation from saintdismas website"));
    } catch (Exception $e) {
        // The card has been declined
        echo "<script>alert(\"Card Has been Declined\");</script>";
        echo "<script>window.location = 'donations.php';</script>";
    }
    if (isset($charge)) {
        $mail = new PHPMailer();
        // $mail->isSMTP();                                      // Set mailer to use SMTP
        // $mail->Host = SMTP_HOST;  // Specify main and backup SMTP servers
        // $mail->SMTPAuth = true;                               // Enable SMTP authentication