Drupal: "Stripe za Drupal v3"
This commit is contained in:
parent
a5a53a324d
commit
466ae22379
@ -47,6 +47,28 @@ function nakupovanje_1ka_menu()
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
//Stripe uspešno plačilo
|
||||||
|
$items['narocilo/stripe'] = [
|
||||||
|
'title' => 'Uspešno plačilo preko Stripe sistema', //page title
|
||||||
|
'description' => 'Plačilo je bilo opravljeno preko Stripe sistema',
|
||||||
|
'page callback' => 'nakupovanje_1ka_stripe_return', //callback function which is invoked when menu item is called.
|
||||||
|
'access callback' => true, //any user can access this page
|
||||||
|
'page arguments' => [
|
||||||
|
1,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
//Stripe cancel
|
||||||
|
$items['narocilo/stripe-cancel'] = [
|
||||||
|
'title' => 'Preklicano plačilo preko Stripe ssistema', //page title
|
||||||
|
'description' => 'Uporabnik je preklical plačilo',
|
||||||
|
'page callback' => 'nakupovanje_1ka_stripe_cancel', //callback function which is invoked when menu item is called.
|
||||||
|
'access callback' => true, //any user can access this page
|
||||||
|
'page arguments' => [
|
||||||
|
1,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
$items['narocilo-pregled/%/pdf'] = [
|
$items['narocilo-pregled/%/pdf'] = [
|
||||||
'title' => 'Uspešno opravljen nakup', //page title
|
'title' => 'Uspešno opravljen nakup', //page title
|
||||||
@ -127,6 +149,24 @@ function nakupovanje_1ka_menu()
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$items['stripe-purchase/success'] = [
|
||||||
|
'title' => 'Successful payment via Stripe', //page title
|
||||||
|
'page callback' => 'nakupovanje_1ka_stripe_return', //callback function which is invoked when menu item is called.
|
||||||
|
'access callback' => true, //any user can access this page
|
||||||
|
'page arguments' => [
|
||||||
|
1,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$items['stripe-purchase/cancel'] = [
|
||||||
|
'title' => 'Payment canceled via Stripe', //page title
|
||||||
|
'page callback' => 'nakupovanje_1ka_stripe_cancel', //callback function which is invoked when menu item is called.
|
||||||
|
'access callback' => true, //any user can access this page
|
||||||
|
'page arguments' => [
|
||||||
|
1,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
$items['purchase/%/package'] = [
|
$items['purchase/%/package'] = [
|
||||||
'title' => 'Purchase of the selected package', //page title
|
'title' => 'Purchase of the selected package', //page title
|
||||||
'page callback' => 'nakupovanje_1ka_kosarica', //callback function which is invoked when menu item is called.
|
'page callback' => 'nakupovanje_1ka_kosarica', //callback function which is invoked when menu item is called.
|
||||||
@ -270,6 +310,17 @@ function nakupovanje_1ka_paypal_cancel()
|
|||||||
return theme('nakupovanje_1ka_paypal_cancel');
|
return theme('nakupovanje_1ka_paypal_cancel');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function nakupovanje_1ka_stripe_return()
|
||||||
|
{
|
||||||
|
return theme('nakupovanje_1ka_stripe_return');
|
||||||
|
}
|
||||||
|
|
||||||
|
function nakupovanje_1ka_stripe_cancel()
|
||||||
|
{
|
||||||
|
return theme('nakupovanje_1ka_stripe_cancel');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function cenik_paketov_1ka_zasebni_uporabniki()
|
function cenik_paketov_1ka_zasebni_uporabniki()
|
||||||
{
|
{
|
||||||
|
@ -765,12 +765,6 @@
|
|||||||
var narocilo = jQuery('#izbria-nacina-placila-1ka [name="narocilo_id"]').val();
|
var narocilo = jQuery('#izbria-nacina-placila-1ka [name="narocilo_id"]').val();
|
||||||
});
|
});
|
||||||
|
|
||||||
//Pri menjavi placila prikazemo ustrezno polje
|
|
||||||
jQuery('[name="payment_method"]').on('change', function () {
|
|
||||||
//Plačilo preko Stripa
|
|
||||||
preverimoZaVrstoPlacila();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Uspešno oddan predračun ali plačilo preko spleta
|
// Uspešno oddan predračun ali plačilo preko spleta
|
||||||
if (jQuery('.narocilo-1ka-pdf').length > 0) {
|
if (jQuery('.narocilo-1ka-pdf').length > 0) {
|
||||||
if (document.cookie.indexOf('pdf=') < 1) {
|
if (document.cookie.indexOf('pdf=') < 1) {
|
||||||
@ -821,6 +815,39 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Stripe plačilo
|
||||||
|
if (
|
||||||
|
(window.location.pathname.indexOf('/narocilo/stripe-cancel') > -1 && location.search.split('narocilo_id=').length > 1) ||
|
||||||
|
(window.location.pathname.indexOf('/stripe-purchase/cancel') > -1 && location.search.split('narocilo_id=').length > 1)
|
||||||
|
) {
|
||||||
|
var parametri = window.location.search.substr(1);
|
||||||
|
|
||||||
|
jQuery.post('/d/nakupovanje-api/cancel_narocilo_stripe', parametri).done(function (val) {
|
||||||
|
val = JSON.parse(val);
|
||||||
|
|
||||||
|
if (val.error) {
|
||||||
|
return jQuery('.procesiram-narocilo').text(val.error);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
(window.location.href.indexOf('/narocilo/stripe?narocilo_id') > -1 && location.search.split('narocilo_id=').length > 1) ||
|
||||||
|
(window.location.href.indexOf('/stripe-purchase/success?narocilo_id') > -1 && location.search.split('narocilo_id=').length > 1)
|
||||||
|
){
|
||||||
|
var parametri = window.location.search.substr(1);
|
||||||
|
|
||||||
|
jQuery.post('/d/nakupovanje-api/stripe_checkout_success', parametri).done(function (val) {
|
||||||
|
val = JSON.parse(val);
|
||||||
|
|
||||||
|
if (val.error) {
|
||||||
|
return jQuery('.procesiram-narocilo').text(val.error);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// jQuery('.accordion-head').on('click', function(){
|
// jQuery('.accordion-head').on('click', function(){
|
||||||
// var st = jQuery(this).attr("data-open");
|
// var st = jQuery(this).attr("data-open");
|
||||||
//
|
//
|
||||||
@ -871,7 +898,6 @@
|
|||||||
|
|
||||||
//Nastavimo prevzeto plačevanje s karticam
|
//Nastavimo prevzeto plačevanje s karticam
|
||||||
jQuery('[name="payment_method"][value="3"]').prop('checked', true);
|
jQuery('[name="payment_method"][value="3"]').prop('checked', true);
|
||||||
preverimoZaVrstoPlacila();
|
|
||||||
|
|
||||||
posodobiCenoPaketa();
|
posodobiCenoPaketa();
|
||||||
}
|
}
|
||||||
@ -1215,11 +1241,7 @@ function oddajNarociloNaStreznik() {
|
|||||||
|
|
||||||
return setTimeout(function(){
|
return setTimeout(function(){
|
||||||
jQuery('.pregled-narocila').show();
|
jQuery('.pregled-narocila').show();
|
||||||
if(jQuery('[name="payment_method"]:checked').val() == 3){
|
jQuery('#oddaj-narocilo').show();
|
||||||
jQuery('#oddaj-stripe').show();
|
|
||||||
} else {
|
|
||||||
jQuery('#oddaj-narocilo').show();
|
|
||||||
}
|
|
||||||
jQuery('.submit-btn.naprej').show();
|
jQuery('.submit-btn.naprej').show();
|
||||||
jQuery('#nazaj-na-nakup-1ka').show();
|
jQuery('#nazaj-na-nakup-1ka').show();
|
||||||
jQuery('.procesiram-narocilo').hide();
|
jQuery('.procesiram-narocilo').hide();
|
||||||
@ -1250,15 +1272,21 @@ function oddajNarociloNaStreznik() {
|
|||||||
|
|
||||||
urlRedirect = val.paypal_link;
|
urlRedirect = val.paypal_link;
|
||||||
|
|
||||||
} else if (paymentMethod > 1) {
|
} else if (paymentMethod == 3) {
|
||||||
document.cookie = "pdf=" + val.racun + ";expires=" + cas + ";path=/";
|
// Nastavimo Stripe instanco
|
||||||
|
var stripe = Stripe(jQuery('.placilo-kartica #stripe-token').val());
|
||||||
|
|
||||||
// Glede na jezik preusmerimo na slovensko oz. angleško verzijo
|
return stripe.redirectToCheckout({ sessionId: val.session_id });
|
||||||
var urlRedirect = "/d/narocilo-pregled/racun/pdf";
|
|
||||||
if (paymentLang == 'en') {
|
|
||||||
urlRedirect = "/d/en/purchase/invoice/pdf";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// else if (paymentMethod > 1) {
|
||||||
|
// document.cookie = "pdf=" + val.racun + ";expires=" + cas + ";path=/";
|
||||||
|
//
|
||||||
|
// // Glede na jezik preusmerimo na slovensko oz. angleško verzijo
|
||||||
|
// var urlRedirect = "/d/narocilo-pregled/racun/pdf";
|
||||||
|
// if (paymentLang == 'en') {
|
||||||
|
// urlRedirect = "/d/en/purchase/invoice/pdf";
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
window.location = urlRedirect;
|
window.location = urlRedirect;
|
||||||
}
|
}
|
||||||
@ -1267,22 +1295,22 @@ function oddajNarociloNaStreznik() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function preverimoZaVrstoPlacila() {
|
// function preverimoZaVrstoPlacila() {
|
||||||
|
//
|
||||||
if (jQuery('[name="payment_method"]:checked').val() == 3) {
|
// if (jQuery('[name="payment_method"]:checked').val() == 3) {
|
||||||
|
//
|
||||||
jQuery('.placilo-kartica').show();
|
// jQuery('.placilo-kartica').show();
|
||||||
jQuery('#oddaj-stripe').show();
|
// jQuery('#oddaj-stripe').show();
|
||||||
jQuery('#oddaj-narocilo').hide();
|
// jQuery('#oddaj-narocilo').hide();
|
||||||
|
//
|
||||||
} else {
|
// } else {
|
||||||
|
//
|
||||||
jQuery('.placilo-kartica').hide();
|
// jQuery('.placilo-kartica').hide();
|
||||||
jQuery('#oddaj-stripe').hide();
|
// jQuery('#oddaj-stripe').hide();
|
||||||
jQuery('#oddaj-narocilo').show();
|
// jQuery('#oddaj-narocilo').show();
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
function posodobiCenoPaketa() {
|
function posodobiCenoPaketa() {
|
||||||
var paket = jQuery('[name="package_id"]:checked').val();
|
var paket = jQuery('[name="package_id"]:checked').val();
|
||||||
@ -1335,7 +1363,6 @@ function posodobiCenoPaketa() {
|
|||||||
if (response['final'] == 0) {
|
if (response['final'] == 0) {
|
||||||
jQuery('.podatki-za-placilo-racuna').hide();
|
jQuery('.podatki-za-placilo-racuna').hide();
|
||||||
jQuery('[name="payment_method"][value="1"]').prop('checked', true);
|
jQuery('[name="payment_method"][value="1"]').prop('checked', true);
|
||||||
preverimoZaVrstoPlacila();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -1347,105 +1374,85 @@ function lang() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Stripe payment
|
//Stripe payment
|
||||||
function cardValidation() {
|
// function cardValidation() {
|
||||||
var valid = true;
|
// var valid = true;
|
||||||
|
//
|
||||||
jQuery('.error-field').removeClass('error-field');
|
// jQuery('.error-field').removeClass('error-field');
|
||||||
|
//
|
||||||
var name = jQuery('.placilo-kartica #stripe-name');
|
// var name = jQuery('.placilo-kartica #stripe-name');
|
||||||
var email = jQuery('#narocilo-paketa-podatki [name="email"]');
|
// var email = jQuery('#narocilo-paketa-podatki [name="email"]');
|
||||||
var cardNumber = jQuery('.placilo-kartica #stripe-card-number');
|
// var cardNumber = jQuery('.placilo-kartica #stripe-card-number');
|
||||||
var month = jQuery('.placilo-kartica #stripe-month');
|
// var month = jQuery('.placilo-kartica #stripe-month');
|
||||||
var year = jQuery('.placilo-kartica #stripe-year');
|
// var year = jQuery('.placilo-kartica #stripe-year');
|
||||||
var cvc = jQuery('.placilo-kartica #stripe-cvc');
|
// var cvc = jQuery('.placilo-kartica #stripe-cvc');
|
||||||
|
//
|
||||||
jQuery("#stripe-error-message").html("").hide();
|
// jQuery("#stripe-error-message").html("").hide();
|
||||||
|
//
|
||||||
if (name.val().trim() == "") {
|
// if (name.val().trim() == "") {
|
||||||
name.addClass('error-field');
|
// name.addClass('error-field');
|
||||||
valid = false;
|
// valid = false;
|
||||||
}
|
// }
|
||||||
if (email.val().trim() == "") {
|
// if (email.val().trim() == "") {
|
||||||
valid = false;
|
// valid = false;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (cardNumber.val().trim() == "") {
|
// if (cardNumber.val().trim() == "") {
|
||||||
cardNumber.addClass('error-field');
|
// cardNumber.addClass('error-field');
|
||||||
valid = false;
|
// valid = false;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (month.val().trim() == "") {
|
// if (month.val().trim() == "") {
|
||||||
month.addClass('error-field');
|
// month.addClass('error-field');
|
||||||
valid = false;
|
// valid = false;
|
||||||
}
|
// }
|
||||||
if (year.val().trim() == "") {
|
// if (year.val().trim() == "") {
|
||||||
year.addClass('error-field');
|
// year.addClass('error-field');
|
||||||
valid = false;
|
// valid = false;
|
||||||
}
|
// }
|
||||||
if (cvc.val().trim() == "") {
|
// if (cvc.val().trim() == "") {
|
||||||
cvc.addClass('error-field');
|
// cvc.addClass('error-field');
|
||||||
valid = false;
|
// valid = false;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (valid == false) {
|
// if (valid == false) {
|
||||||
var opozorilo = "Vsa polja so obvezna!";
|
// var opozorilo = "Vsa polja so obvezna!";
|
||||||
if (lang() == 'en') {
|
// if (lang() == 'en') {
|
||||||
opozorilo = "All Fields are required!";
|
// opozorilo = "All Fields are required!";
|
||||||
}
|
// }
|
||||||
jQuery("#stripe-error-message").html(opozorilo).show();
|
// jQuery("#stripe-error-message").html(opozorilo).show();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return valid;
|
// return valid;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
function stripePay(e) {
|
// function stripePay(narociloId) {
|
||||||
e.preventDefault();
|
// var narociloId = narociloId || 0;
|
||||||
|
//
|
||||||
// V kolikor je omenjeno polje izpolnjeno potem gre za robota in preusmerimo na začetno stran
|
// // Create an instance of the Stripe object with your publishable API key
|
||||||
if (jQuery('[name="stripe-robotsko-narocilo"]').val().length > 0) {
|
// var stripe = Stripe(jQuery('.placilo-kartica #stripe-token').val());
|
||||||
return window.location = '/';
|
//
|
||||||
}
|
// return stripe.redirectToCheckout({ sessionId: narociloId });
|
||||||
|
// }
|
||||||
var valid = cardValidation();
|
|
||||||
|
|
||||||
if (valid == true) {
|
|
||||||
jQuery(".submit-btn").hide();
|
|
||||||
jQuery("#nazaj-na-nakup-1ka").hide();
|
|
||||||
// jQuery( "#loader" ).css("display", "inline-block");
|
|
||||||
|
|
||||||
Stripe.setPublishableKey(jQuery('.placilo-kartica #stripe-token').val());
|
|
||||||
|
|
||||||
Stripe.createToken({
|
|
||||||
number: jQuery('.placilo-kartica #stripe-card-number').val(),
|
|
||||||
cvc: jQuery('.placilo-kartica #stripe-cvc').val(),
|
|
||||||
exp_month: jQuery('.placilo-kartica #stripe-month').val(),
|
|
||||||
exp_year: jQuery('.placilo-kartica #stripe-year').val()
|
|
||||||
}, stripeResponseHandler);
|
|
||||||
|
|
||||||
//submit from callback
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//callback to handle the response from stripe
|
//callback to handle the response from stripe
|
||||||
function stripeResponseHandler(status, response) {
|
// function stripeResponseHandler(status, response) {
|
||||||
if (response.error) {
|
// if (response.error) {
|
||||||
//enable the submit button
|
// //enable the submit button
|
||||||
jQuery('#oddaj-stripe').show();
|
// jQuery('#oddaj-stripe').show();
|
||||||
|
//
|
||||||
jQuery("#loader").css("display", "none");
|
// jQuery("#loader").css("display", "none");
|
||||||
|
//
|
||||||
//display the errors on the form
|
// //display the errors on the form
|
||||||
jQuery("#stripe-error-message").html(response.error.message).show();
|
// jQuery("#stripe-error-message").html(response.error.message).show();
|
||||||
} else {
|
// } else {
|
||||||
//get token id
|
// //get token id
|
||||||
var token = response['id'];
|
// var token = response['id'];
|
||||||
|
//
|
||||||
//insert the token into the form
|
// //insert the token into the form
|
||||||
jQuery('#narocilo-paketa-podatki').append("<input type='hidden' name='stripe_id' value='" + token + "' />");
|
// jQuery('#narocilo-paketa-podatki').append("<input type='hidden' name='stripe_id' value='" + token + "' />");
|
||||||
|
//
|
||||||
//submit form to the server
|
// //submit form to the server
|
||||||
oddajNarociloNaStreznik();
|
// oddajNarociloNaStreznik();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
@ -150,7 +150,7 @@ function pro1ka_preprocess_html(&$variables) {
|
|||||||
|
|
||||||
// JS external
|
// JS external
|
||||||
drupal_add_js('https://www.google.com/recaptcha/api.js', array('group' => JS_THEME));
|
drupal_add_js('https://www.google.com/recaptcha/api.js', array('group' => JS_THEME));
|
||||||
drupal_add_js('https://js.stripe.com/v2/', array('group' => JS_THEME));
|
drupal_add_js('https://js.stripe.com/v3/', array('group' => JS_THEME));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
<?php global $language; ?>
|
||||||
|
|
||||||
|
<div id="narocilo-1ka-cancel-paypal">
|
||||||
|
|
||||||
|
<div style="padding: 2rem 0;">
|
||||||
|
<p>
|
||||||
|
<?php if ($language->language == 'sl'): ?>
|
||||||
|
Vaše naročilo je preklicano. Če želite ponovno oddati naročilo (spremeniti način plačila ali izbrati drug paket), kliknite na <a href="/d/sl/cenik/zasebni-paketi">povezavo</a>.
|
||||||
|
<?php else: ?>
|
||||||
|
Your order has been canceled. Click the <a href="/d/en/price-list/private-packages">link</a> to resubmit your order (change your payment method or choose another package).
|
||||||
|
<?php endif; ?>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="w-clearfix bottom-buttons">
|
||||||
|
<div class="col" style="float: left;">
|
||||||
|
<?php if ($language->language == 'sl'): ?>
|
||||||
|
<a href="/d/sl" class="w-link-button">Vrni se na naslovno stran</a>
|
||||||
|
<?php else: ?>
|
||||||
|
<a href="/d/en" class="w-link-button">Return to home page</a>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
@ -0,0 +1,34 @@
|
|||||||
|
<?php global $language; ?>
|
||||||
|
|
||||||
|
|
||||||
|
<div id="narocilo-1ka-return-paypal">
|
||||||
|
|
||||||
|
<div style="padding: 2rem 0;">
|
||||||
|
<p>
|
||||||
|
<?php if ($language->language == 'sl'): ?>
|
||||||
|
Zahvaljujemo se vam za vaš nakup preko Stripe plačilnea sistema. Vaš novi paket je aktiven in ga lahko pričnete uporabljati.
|
||||||
|
<?php else: ?>
|
||||||
|
Thank you for your purchase using Strpe! Your new package is now active and you can use it.
|
||||||
|
<?php endif; ?>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="w-clearfix bottom-buttons">
|
||||||
|
<div class="col" style="float: right;">
|
||||||
|
<?php if ($language->language == 'sl'): ?>
|
||||||
|
<a href="/admin/survey" class="submit-btn w-button">Ustvari anketo</a>
|
||||||
|
<?php else: ?>
|
||||||
|
<a href="/admin/survey/index.php?lang=en" class="submit-btn w-button">Create a survey</a>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col" style="float: left;">
|
||||||
|
<?php if ($language->language == 'sl'): ?>
|
||||||
|
<a href="/" class="w-link-button">Vrni se na naslovno stran</a>
|
||||||
|
<?php else: ?>
|
||||||
|
<a href="/d/en" class="w-link-button">Return to home page</a>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
Loading…
x
Reference in New Issue
Block a user