Skip to main content

Stripe

########### PAYMENT GATEWAY TYPES ###########
Sites in test mode connect to “Sandbox” gateways. ...
Sites in production mode connect to “Live” gateways.

__________________________________________________


https://stackoverflow.com/questions/25546372/stripe-payment-gateway-i-wants-to-use-amount-in-decimal-format
https://stripe.com/docs/recipes/variable-amount-checkout

__________________________________________________

{"id":"card_1E3MaZL09KjGnQBSE9GRBAXI","object":"card","address_city":null,"address_country":null,"address_line1":null,"address_line1_check":null,"address_line2":null,"address_state":null,"address_zip":null,"address_zip_check":null,"brand":"Visa","country":"US","customer":"cus_EWPPANFUwvgE6Y","cvc_check":"pass","dynamic_last4":null,"exp_month":3,"exp_year":2021,"fingerprint":"sLxubtQ4jOOqHpQj","funding":"credit","last4":"4242","metadata":[],"name":null,"tokenization_method":null}
_____________________________________________________
***** testservice.php ******
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Testservice extends CI_Controller {

public function __construct($config = 'rest')
{
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
parent::__construct();
}
  public function signup(){   
   
$email = (trim($this->input->get('email')));
$password = md5($this->input->get('password'));
$contact = (trim($this->input->get('contact')));
$username = (trim($this->input->get('username')));
$token = (trim($this->input->get('stripeToken')));
$role = 'user';

        // Create USER on Stripe
        require_once('stripe_payment_gateway/stripe-php/init.php');
       
        $keys = $this->user_model->get_joins('admin_stripe');
   
        //   $stripe = array(
        //     "secret_key"      => "$keys[0]['secretkey']",
        //     "publishable_key" => "$keys[0]['publishablekey']"
        //   );
       
          $stripe = array(
        "secret_key"      => "sk_test_bBcx24ld9rsUmP5kd1nNUS43",
        "publishable_key" => "pk_test_6C2zhCPDkgYTCvlU96n2WcIw"
      );
       
       
       
        \Stripe\Stripe::setApiKey($stripe['secret_key']);
   
        // Create a Customer:
        $customer = \Stripe\Customer::create([
            'source' => $token,
            'email' => $email,
        ]);


$insertdata = array(
'email' => $email,
'password' => $password,
'contact' => $contact,
'username' => $username,
'role'=>$role,
'date' => date('Y-m-d h:i:s'),
'stripecustomerid' => $customer->id
);

print_r($insertdata);

   
}
?>
***** Create User.php **********
<html>
  <head>
    <title> Create Stripe User </title>

  </head>
  <body>
    <h5> Card details </h5> 
<span class="payment-errors text-danger"></span>
   <form id="paymentFrm" action="http://api.hairstylist.betaplanets.com/testservice/signup" method="get" > 
    <input type="text" name="email" autocomplete="off" placeholder="email" >
    <input type="text" name="username" autocomplete="off"  placeholder="username" >   
      <!-- <strong>Card Number : </strong> -->
      <input type="text" name="card_num" autocomplete="off" class="card-number" size="15" placeholder="card_num" >       
      <!-- <strong>CVC : </strong> -->
      <input placeholder="cvc" type="text" name="cvc" autocomplete="off" class="card-cvc" size="3">
      <!-- <strong>Expiration (MM/YYYY) : </strong> -->
      <input placeholder="exp_month" type="month" name="exp_month" size="2" class="card-expiry-month"/>
      <input placeholder="exp_year"  type="year" name="exp_year" size="4" class="card-expiry-year"/> 
    <button type="submit" id="payBtn" class="btn btn-primary btn-sm"> Submit Payment </button>
    </form>             

    <!-- Stripe JavaScript library -->
  <script type="text/javascript" src="https://js.stripe.com/v2/"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script type="text/javascript">
        //set your publishable key
        Stripe.setPublishableKey('pk_test_6C2zhCPDkgYTCvlU96n2WcIw');
        //callback to handle the response from stripe
        function stripeResponseHandler(status, response) {
            if (response.error) {
                //enable the submit button
                $('#payBtn').removeAttr("disabled");
                //display the errors on the form
                $(".payment-errors").html(response.error.message);
            } else {
                var form$ = $("#paymentFrm");
                //get token id
                var token = response['id'];
                //insert the token into the form
                form$.append("<input type='hidden' name='stripeToken' value='" + token + "' />");
                //submit form to the server
                form$.get(0).submit();
            }
        }
        $(document).ready(function() {
            //on form submit
            $("#paymentFrm").submit(function(event) {
                //disable the submit button to prevent repeated clicks
                $('#payBtn').attr("disabled", "disabled");
               
                //create single-use token to charge the user
                Stripe.createToken({
                    number: $('.card-number').val(),
                    cvc: $('.card-cvc').val(),
                    exp_month: $('.card-expiry-month').val(),
                    exp_year: $('.card-expiry-year').val()
                }, stripeResponseHandler);
               
                //submit from callback
                return false;
            });
        });
  </script>
  </body>

</html>
___________________________________________________________________________
## USER APP SIGNUP
public function signup(){
$email = (trim($this->input->get('email')));
$password = md5($this->input->get('password'));
$contact = (trim($this->input->get('contact')));
$username = (trim($this->input->get('username')));
$token = (trim($this->input->get('stripeToken')));
$role = 'user';

// Create USER on Stripe
        require_once('stripe_payment_gateway/stripe-php/init.php');
       
        $keys = $this->user_model->get_joins('admin_stripe');
   
          $stripe = array(
            "secret_key"      => "$keys[0]['secretkey']",
            "publishable_key" => "$keys[0]['publishablekey']"
          );


  //     $stripe = array(
    //     "secret_key"      => "sk_test_bBcx24ld9rsUmP5kd1nNUS43",
    //     "publishable_key" => "pk_test_6C2zhCPDkgYTCvlU96n2WcIw"
    //   );
       



        \Stripe\Stripe::setApiKey($stripe['secret_key']);
   
        // Create a Customer:
        $customer = \Stripe\Customer::create([
            'source' => $token,
            'email' => $email,
        ]);
$insertdata = array(
'email' => $email,
'password' => $password,
'contact' => $contact,
'username' => $username,
'role'=>$role,
'date' => date('Y-m-d h:i:s'),
'stripecustomerid' => $customer->id
);

$where_contact = array(
'contact' => $contact,
'username' => $username
);
$user_contact = ($this->user_model->get_joins('user', '','','','','','','','',$where_contact));
if (!empty($user_contact)){
echo "User & Contact is already registered";
}else{
$is_insert = $this->user_model->INSERTDATA('user', $insertdata);
if ($is_insert){
echo "true";
}else{
echo "Registration Failed";
}
}
}




Comments

Popular posts from this blog

SETUP REST API IN CI

1. Create Rest_controller.php inside controllers and paste code: <?php defined('BASEPATH') OR exit('No direct script access allowed'); require APPPATH . '/libraries/API_Controller.php'; class Rest_controller extends API_Controller { public function __construct() { parent::__construct(); } public function index() { $this->api_return(             [ 'status' => true,                'result' => "Welcome to Testservices."             ],         200); } } ?> 2. Create api.php inside config and paste code : <?php defined('BASEPATH') OR exit('No direct script access allowed'); /**  * API Key Header Name  */ $config['api_key_header_name'] = 'X-API-KEY'; /**  * API Key GET Request Parameter Name  */ $config['api_key_get_name'] = 'key'; /**  * API Key POST Request Parameter Name ...

NGrok Setup

 https://dashboard.ngrok.com/get-started/setup 1. Unzip to install On Linux or Mac OS X you can unzip ngrok from a terminal with the following command. On Windows, just double click ngrok.zip to extract it. unzip /path/to/ngrok.zip 2. Connect your account Running this command will add your authtoken to the default ngrok.yml configuration file. This will grant you access to more features and longer session times. Running tunnels will be listed on the endpoints page of the dashboard. ngrok config add-authtoken 1woFn9zVqcI4VeGuSIiN2VtmnPa_ZXuAuF1AAPkqApr7WVsQ 3. Fire it up Read the documentation on how to use ngrok. Try it out by running it from the command line: ngrok help To start a HTTP tunnel forwarding to your local port 80, run this next: ngrok http 80

API ( service ) Image or Video Upload

## SAVE  VIDEO public function uploadmedia() { $target_path = "assets/uploads/"; $target_path = $target_path . basename($_FILES['file']['name']); if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) { $this->api_return( [ 'status' => true,    'result' => 'uploaded success' ], 200); } else{ $this->api_return( [ 'status' => false,    'result' => 'failed' ], 20); } } ## SAVE FILE IMAGE OR VIDEO public function savefile() { $filetype = $_FILES['file']['type']; if (strpos($filetype, 'image') !== false) { $type = 'image'; } if (strpos($filetype, 'video') !== false) { $type = 'video'; }         $filename = trim($_FILES['file']['name']); // $userid = trim($this->input->get('userid'));...