########### 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";
}
}
}
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
Post a Comment