-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
415 changed files
with
40,665 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<button id="rzp-button1">Pay</button> | ||
<script src="https://checkout.razorpay.com/v1/checkout.js"></script> | ||
<script> | ||
var options = { | ||
"key": "rzp_test_tG1krcZ5CdLY16", // Enter the Key ID generated from the Dashboard | ||
"amount": "50000", // Amount is in currency subunits. Default currency is INR. Hence, 50000 refers to 50000 paise | ||
"currency": "INR", | ||
"name": "Acme Corp", | ||
"description": "Test Transaction", | ||
"image": "https://example.com/your_logo", | ||
"order_id": "order_HllBgrsWMo15ZN", //This is a sample Order ID. Pass the `id` obtained in the response of Step 1 | ||
"tax":18, | ||
"handler": function (response){ | ||
alert(response.razorpay_payment_id); | ||
alert(response.razorpay_order_id); | ||
alert(response.razorpay_signature) | ||
}, | ||
"prefill": { | ||
"name": "Gaurav Kumar", | ||
"email": "[email protected]", | ||
"contact": "9999999999" | ||
}, | ||
"notes": { | ||
"address": "Razorpay Corporate Office" | ||
}, | ||
"theme": { | ||
"color": "#3399cc" | ||
} | ||
}; | ||
var rzp1 = new Razorpay(options); | ||
rzp1.on('payment.failed', function (response){ | ||
alert(response.error.code); | ||
alert(response.error.description); | ||
alert(response.error.source); | ||
alert(response.error.step); | ||
alert(response.error.reason); | ||
alert(response.error.metadata.order_id); | ||
alert(response.error.metadata.payment_id); | ||
}); | ||
document.getElementById('rzp-button1').onclick = function(e){ | ||
rzp1.open(); | ||
e.preventDefault(); | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Accept a Card Payment | ||
|
||
Build a simple checkout form to collect card details. Included are some basic build and run scripts you can use to start up the application. | ||
|
||
## Running the sample | ||
|
||
1. Build the server | ||
|
||
``` | ||
composer install | ||
``` | ||
|
||
2. Run the server | ||
|
||
``` | ||
php -S 127.0.0.1:4242 | ||
``` | ||
|
||
3. Go to [http://localhost:4242/checkout.html](http://localhost:4242/checkout.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"require": { | ||
"stripe/stripe-php": "^6.31" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
require 'vendor/autoload.php'; | ||
|
||
// This is your real test secret API key. | ||
\Stripe\Stripe::setApiKey('sk_test_51JP4RPSAdz1LKj9Xa4ima4xO7S2IcaFSqvVXHVnbvhV2CKxSQiaB0BbF1wssRaQaBMrkEcrRIhoDF7epMSd91bOk00wJUr0r1g'); | ||
|
||
|
||
function calculateOrderAmount(array $items): int { | ||
// Replace this constant with a calculation of the order's amount | ||
// Calculate the order total on the server to prevent | ||
// customers from directly manipulating the amount on the client | ||
return 1400; | ||
} | ||
|
||
header('Content-Type: application/json'); | ||
|
||
try { | ||
// retrieve JSON from POST body | ||
$json_str = file_get_contents('php://input'); | ||
$json_obj = json_decode($json_str); | ||
|
||
$paymentIntent = \Stripe\PaymentIntent::create([ | ||
'amount' => calculateOrderAmount($json_obj->items), | ||
'currency' => 'inr', | ||
'description' => 'Software development services', | ||
|
||
]); | ||
|
||
$output = [ | ||
'clientSecret' => $paymentIntent->client_secret, | ||
]; | ||
|
||
echo json_encode($output); | ||
} catch (Error $e) { | ||
http_response_code(500); | ||
echo json_encode(['error' => $e->getMessage()]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Accept a card payment</title> | ||
<meta name="description" content="A demo of a card payment on Stripe" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
|
||
<link rel="stylesheet" href="/stripe/public/global.css" /> | ||
<script src="https://js.stripe.com/v3/"></script> | ||
<script src="https://polyfill.io/v3/polyfill.min.js?version=3.52.1&features=fetch"></script> | ||
<script src="/stripe/public/client.js" defer></script> | ||
</head> | ||
|
||
<body> | ||
<!-- Display a payment form --> | ||
<form id="payment-form"> | ||
<div id="card-element"><!--Stripe.js injects the Card Element--></div> | ||
<button id="submit"> | ||
<div class="spinner hidden" id="spinner"></div> | ||
<span id="button-text">Pay now</span> | ||
</button> | ||
<p id="card-error" role="alert"></p> | ||
<p class="result-message hidden"> | ||
Payment succeeded, see the result in your | ||
<a href="" target="_blank">Stripe dashboard.</a> Refresh the page to pay again. | ||
</p> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// A reference to Stripe.js initialized with your real test publishable API key. | ||
var stripe = Stripe("pk_test_51JP4RPSAdz1LKj9XZExhumPfL5AxjYouxGxPhtyEcOBVlJnT4FnM59D40xS0lgl7LY8ADSQyKq0uMycB5AtEDPZQ00uINSHR0V"); | ||
|
||
// The items the customer wants to buy | ||
var purchase = { | ||
items: [{ id: "xl-tshirt" }] | ||
}; | ||
|
||
// Disable the button until we have Stripe set up on the page | ||
document.querySelector("button").disabled = true; | ||
fetch("/stripe/create.php", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json" | ||
}, | ||
body: JSON.stringify(purchase) | ||
}) | ||
.then(function(result) { | ||
return result.json(); | ||
}) | ||
.then(function(data) { | ||
var elements = stripe.elements(); | ||
|
||
var style = { | ||
base: { | ||
color: "#32325d", | ||
fontFamily: 'Arial, sans-serif', | ||
fontSmoothing: "antialiased", | ||
fontSize: "16px", | ||
"::placeholder": { | ||
color: "#32325d" | ||
} | ||
}, | ||
invalid: { | ||
fontFamily: 'Arial, sans-serif', | ||
color: "#fa755a", | ||
iconColor: "#fa755a" | ||
} | ||
}; | ||
|
||
var card = elements.create("card", { style: style }); | ||
// Stripe injects an iframe into the DOM | ||
card.mount("#card-element"); | ||
|
||
card.on("change", function (event) { | ||
// Disable the Pay button if there are no card details in the Element | ||
document.querySelector("button").disabled = event.empty; | ||
document.querySelector("#card-error").textContent = event.error ? event.error.message : ""; | ||
}); | ||
|
||
var form = document.getElementById("payment-form"); | ||
form.addEventListener("submit", function(event) { | ||
event.preventDefault(); | ||
// Complete payment when the submit button is clicked | ||
payWithCard(stripe, card, data.clientSecret); | ||
}); | ||
}); | ||
|
||
// Calls stripe.confirmCardPayment | ||
// If the card requires authentication Stripe shows a pop-up modal to | ||
// prompt the user to enter authentication details without leaving your page. | ||
var payWithCard = function(stripe, card, clientSecret) { | ||
loading(true); | ||
stripe | ||
.confirmCardPayment(clientSecret, { | ||
payment_method: { | ||
card: card | ||
} | ||
}) | ||
.then(function(result) { | ||
if (result.error) { | ||
// Show error to your customer | ||
showError(result.error.message); | ||
} else { | ||
// The payment succeeded! | ||
orderComplete(result.paymentIntent.id); | ||
} | ||
}); | ||
}; | ||
|
||
/* ------- UI helpers ------- */ | ||
|
||
// Shows a success message when the payment is complete | ||
var orderComplete = function(paymentIntentId) { | ||
loading(false); | ||
document | ||
.querySelector(".result-message a") | ||
.setAttribute( | ||
"href", | ||
"https://dashboard.stripe.com/test/payments/" + paymentIntentId | ||
); | ||
document.querySelector(".result-message").classList.remove("hidden"); | ||
document.querySelector("button").disabled = true; | ||
}; | ||
|
||
// Show the customer the error from Stripe if their card fails to charge | ||
var showError = function(errorMsgText) { | ||
loading(false); | ||
var errorMsg = document.querySelector("#card-error"); | ||
errorMsg.textContent = errorMsgText; | ||
setTimeout(function() { | ||
errorMsg.textContent = ""; | ||
}, 4000); | ||
}; | ||
|
||
// Show a spinner on payment submission | ||
var loading = function(isLoading) { | ||
if (isLoading) { | ||
// Disable the button and show a spinner | ||
document.querySelector("button").disabled = true; | ||
document.querySelector("#spinner").classList.remove("hidden"); | ||
document.querySelector("#button-text").classList.add("hidden"); | ||
} else { | ||
document.querySelector("button").disabled = false; | ||
document.querySelector("#spinner").classList.add("hidden"); | ||
document.querySelector("#button-text").classList.remove("hidden"); | ||
} | ||
}; |
Oops, something went wrong.