Stripe API. Pasarela de Cobro en PHP Implementaciones para desarrolladores


Origen: Dashboard

 

Ejemplo de Página de Checkout (No está probado)

Hay que descargar composer, stripe.php, Libreria PHP 7.1.7

index.php

<?php require_once(‘./config.php’); ?>

 

config.php

<?php
php composer-setup.php –install-dir=bin;
php composer-setup.php –version=1.4.2-alpha8 –filename=composer;
require_once(‘stripe-php/init.php’);
require_once(‘vendor/autoload.php’);
$stripe = array(
secret_key => getenv(‘sk_test_Tuclave’),
publishable_key => getenv(‘pk_test_Tuclave’)
);
\Stripe\Stripe::setApiKey($stripe[‘secret_key’]);
?>

checkout.php (Con Claves de Pruebas pk_test_Tuclave, sk_test_Tuclave)

<?php

{
“require”: {
“stripe/stripe-php”: “5.*”
}
};

 

$stripe = array(
“secret_key” => “sk_test_Tuclave”,
“publishable_key” => “pk_test_Tuclave”
);

require_once(‘config.php’);

\Stripe\Stripe::setApiKey($stripe[‘secret_key’]);

$token = $_POST[‘stripeToken’];  //No se utiliza aquí

 

//Boton de Cobro

<form action=” method=”POST”>
https://checkout.stripe.com/v2/checkout.js
</form>

 

// Formulario de Entrada

<form action=” method=”POST” id=”payment-form”>
<span class=”payment-errors”></span>

Card Number

CVC

Expiration (MM/YYYY)

<button type=”submit”>Buy Now</button>
</form>

//Clave Publica

//code.jquery.com/jquery-2.0.2.min.js
//js.stripe.com/v2/

(function() {
Stripe.setPublishableKey(‘pk_test_Tuclave’);
})();

 

// Event Listeners Token  (testigo)

$(‘#payment-form’).on(‘submit’, generateToken);

var generateToken = function(e) {
var form = $(this);

// No pressing the buy now button more than once
form.find(‘button’).prop(‘disabled’, true);

// Create the token, based on the form object
Stripe.create(form, stripeResponseHandler);

// Prevent the form from submitting
e.preventDefault();
};

var stripeResponseHandler = function(status, response) {};

// Respuesta del Token

var stripeResponseHandler = function(status, response) {
var form = $(‘#payment-form’);

// Any validation errors?
if (response.error) {
// Show the user what they did wrong
form.find(‘.payment-errors’).text(response.error.message);

// Make the submit clickable again
form.find(‘button’).prop(‘disabled’, false);
} else {
// Otherwise, we’re good to go! Submit the form.

// Insert the unique token into the form
$(‘<input>’, {
‘type’: ‘hidden’,
‘name’: ‘stripeToken’,
‘value’: response.id
}).appendTo(form);

// Call the native submit method on the form
// to keep the submission from being canceled
form.get(0).submit();
}
};

 

// Set your API key

 

Stripe::setApiKey(“sk_test_Tuclave”);

try {
Stripe_Charge::create([
‘amount’ => 2000, // this is in cents: $20
‘currency’ => ‘usd’,
‘card’ => $_POST[‘stripeToken’],
‘description’ => ‘Describe your product’
]);
} catch (Stripe_CardError $e) {
// Declined. Don’t process their purchase.
// Go back, and tell the user to try a new card
}

?>

Ejemplo de de Checkout

?php

{
“require”: {
“stripe/stripe-php”: “5.*”
}
};
require_once(‘vendor/autoload.php’);

$stripe = array(
“secret_key” => “sk_test_Tuclave”,
“publishable_key” => “pk_test_Tuclave”
);

\Stripe\Stripe::setApiKey($stripe[‘secret_key’]);

$token = $_POST[‘stripeToken’];

$customer = \Stripe\Customer::create(array(
‘email’ => ‘customer@example.com’,
‘source’ => $token
));

https://checkout.stripe.com/checkout.js

Pay Your Deposit

<input name=”patient_email” class=”forms” type=”text” placeholder=”Your Email”>
<input name=”mobile_number” class=”forms” type=”text” placeholder=”Mobile Number”>

var mobile_number = ”;

var handler = StripeCheckout.configure({ key: ‘pk_test_Tuclave’,

// publishable key token: function(token, args) { chargeToken(token, args); } }); jQuery
(document).on(‘click’, ‘#submitPayment’,

function(e) { var mobile_number = jQuery(‘input[name=mobile_number]’).val();

var patient_first_name = jQuery(‘input[name=patient_first_name]’).val();
var patient_surname = jQuery(‘input[name=patient_surname]’).val();
var patient_email = jQuery(‘input[name=patient_email]’).val();

if(patient_first_name == ”) { alert(“Your first name can’t be left blank!”); return false;
} if(patient_surname == ”) { alert(“Your surname can’t be left blank!”); return false; }
if(patient_email == ”) { alert(“Your Email can’t be left blank !”); return false; } var
regex = /^[0-9]\d*(((,\d{3}){1})?(.\d{0,2})?)$/; if(mobile_number == “”) { alert(“Mobile
Number can’t be left blank !”); return false; } if (patient_first_name !== ” &&
patient_surname !== ” && mobile_number !== ” && patient_email !== ”)

{ // Open Checkout with further options

handler.open({ name: ‘Appointment Deposit’, email: patient_email, description:
patient_first_name + ‘ ‘ + patient_surname + ‘ | ‘ + mobile_number,

amount: 2500, currency: ‘USD’,  // 25.00 USD a cobrar

image: ‘http://www.nw1dentalcare.co.uk/wp-content/uploads/2016/09/logo-square.png&#8217; }); }

e.preventDefault(); });

// Close Checkout on page navigation

jQuery(window).on(‘popstate’, function() { handler.close(); });

function chargeToken(token, addresses)

{ var mobile_number = jQuery(‘input[name=mobile_number]’).val(); var patient_first_name =
jQuery(‘input[name=patient_first_name]’).val(); var patient_surname = jQuery(‘input
[name=patient_surname]’).val(); var patient_email = jQuery(‘input[name=patient_email]’).val
(); jQuery.ajax({ type: ‘POST’, url: ‘http://www.nw1dentalcare.co.uk/stripe/charge.php&#8217;,
data: {tokenid: token.id, email: patient_email, amount: 25, description: patient_first_name
+ ‘ ‘ + patient_surname + ‘ | ‘ + mobile_number}, dataType: ‘json’, success: function
(response) { if (response[‘type’] == “1”)

{ alert(‘Payment successfully made! Call us now to set an appointment.’); } else { alert
(‘Payment could not be processed. Please try again.’); location.reload(); } } }); }
<button id=”submitPayment” class=”go-btn”>Pay Your $25 Appointment
Deposit</button> </div>

?>

// Adicional Generar echo para cualquiera de las variables (no es de este ejemplo.

echo “post: <pre>”; print_r($_POST) ; echo “</pre>”;
echo “customer: <pre>”; print_r($customer) ; echo “</pre>”;
echo “charge: <pre>”; print_r($charge) ; echo “</pre>”;

Anuncios

Acerca de UniSoft-AleBo

La tecnología a tu alcance Asesorías Científico - Metodológicas http://plc.site11.com
Esta entrada fue publicada en Capacitación, Diseño Web, Servicios, Softwares, Ventas, Web 2.0. Guarda el enlace permanente.

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s