Forum arrow_forward_ios Codding

Questions By
Monjoti Mondol
card_giftcard ₹0

question_answer How to integrate STRIPE with PHP on my website?

I want to integrate STRIPE payment gateway on my website using PHP.

How to do it?

I need full code, please explain me in simple understanding codes.

12-12-2019, Total 1 Ans , 200 views


more_horiz Other Answers

Firstly you  need to install the STRIPE PHP SDK composer on your website, and it should be on your website's folder.

You can check this about installing the composer.

https://stripe.com/docs/payments/accept-a-payment#php

Ok Here is the codes -

HTML

<script src="https://js.stripe.com/v3/"></script> <div > <form action="test4.php" method="post" id="payment-form"> <div class="form-row"> <label for="card-element" style="color:#2980b9 ;" > Pay with Credit or debit card </label> <br/><br/> <div id="card-element"> <-- A Stripe Element will be inserted here. --> </div> <-- Used to display form errors. --> <div id="card-errors" role="alert" class="text-danger" style="margin-top:10px;margin-bottom:10px;"></div> <br/> <button>Pay now</button> </div> </form> </div>

CSS

/** * The CSS shown here will not be introduced in the Quickstart guide, but shows * how you can use CSS to style your Element's container. */ .StripeElement { box-sizing: border-box; height: 40px; padding: 10px 12px; border: 1px solid transparent; border-radius: 4px; background-color: white; box-shadow: 0 1px 3px 0 #e6ebf1; -webkit-transition: box-shadow 150ms ease; transition: box-shadow 150ms ease; } .StripeElement--focus { box-shadow: 0 1px 3px 0 #cfd7df; } .StripeElement--invalid { border-color: #fa755a; } .StripeElement--webkit-autofill { background-color: #fefde5 important; } .form-row{ border:1px solid lightgray; padding:10px; } .card-element{ border:1px solid lightgray; }

JavaScript

// Create a Stripe client. var stripe = Stripe('pk_test_yourkey'); // Create an instance of Elements. var elements = stripe.elements(); // Custom styling can be passed to options when creating an Element. // (Note that this demo uses a wider set of styles than the guide below.) var style = { base: { color: '#32325d', fontFamily: '"Helvetica Neue", Helvetica, sans-serif', fontSmoothing: 'antialiased', fontSize: '16px', '::placeholder': { color: '#aab7c4' } }, invalid: { color: '#fa755a', iconColor: '#fa755a' } }; // Create an instance of the card Element. var card = elements.create('card', {style: style}); // Add an instance of the card Element into the `card-element` <div>. card.mount('#card-element'); // Handle real-time validation errors from the card Element. card.addEventListener('change', function(event) { var displayError = document.getElementById('card-errors'); if (event.error) { displayError.textContent = event.error.message; } else { displayError.textContent = ''; } }); // Handle form submission. var form = document.getElementById('payment-form'); form.addEventListener('submit', function(event) { event.preventDefault(); stripe.createToken(card).then(function(result) { if (result.error) { // Inform the user if there was an error. var errorElement = document.getElementById('card-errors'); errorElement.textContent = result.error.message; } else { // Send the token to your server. stripeTokenHandler(result.token); } }); }); // Submit the form with the token ID. function stripeTokenHandler(token) { // Insert the token ID into the form so it gets submitted to the server var form = document.getElementById('payment-form'); var hiddenInput = document.createElement('input'); hiddenInput.setAttribute('type', 'hidden'); hiddenInput.setAttribute('name', 'stripeToken'); hiddenInput.setAttribute('value', token.id); form.appendChild(hiddenInput); // Submit the form form.submit(); }

PHP

if(isset($_POST['stripeToken'])){ include "vendor/autoload.php"; // Set your secret key: remember to change this to your live secret key in production // See your keys here: https://dashboard.stripe.com/account/apikeys \Stripe\Stripe::setApiKey('sk_test_yourkey'); // Token is created using Checkout or Elements // Get the payment token ID submitted by the form: $token = $_POST['stripeToken']; // `source` is obtained with Stripe.js; see https://stripe.com/docs/payments/accept-a-payment-charges#web-create-token $charge = \Stripe\Charge::create([ 'amount' => 2000, 'currency' => 'inr', 'source' => $token, 'description' => 'Charge for jenny.rosen@example.com', ]); //print_r($charge); // Retrieve charge details $chargeJson = $charge->jsonSerialize(); // Check whether the charge is successful if($chargeJson['status']=='succeeded'){ echo "OK"; }else{ echo "NO"; } }


And If the PHP doesn't work, change the currency with your country currency.

Change this

'currency' => 'inr',

Hopped this helped you.



Mritunjoy Mushahary
12-12-2019

Please lock LOGIN to Answer

announcement Recently Asked

question_answer
question_answer
question_answer


announcement Related Ques

question_answer
question_answer
question_answer
question_answer
question_answer
How to get date of every after 30 days using PHP?
Ans(1) ₹0 check_circle_outline
question_answer
How to get the nested Array Data using PHP?
Ans(1) ₹0 check_circle_outline
question_answer
How to properly get Pre Signed URL from s3 Bucket?
Ans(1) ₹0 check_circle_outline
question_answer
How much is the Margin Money of PMEGP Loan fo ST?
Ans(1) ₹0 check_circle_outline
question_answer
I want to register SENDER ID for my SNS SMS, on AWS.
Ans(1) ₹0 check_circle_outline
question_answer
Which is the right time to get EDP Training?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
How much Amazon Cloud Hosting charges?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
php count variable values separated with comma
Ans(2) ₹0 check_circle_outline
question_answer
question_answer
question_answer
question_answer
error timezone php or set time php timezone
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
question_answer
question_answer
question_answer
What were the documents required for PMEGP Loan?
Ans(1) ₹0 check_circle_outline
question_answer
How to get the present full url using PHP
Ans(2) ₹0 check_circle_outline
question_answer
question_answer
How to transfer data from one website to another?
Ans(2) ₹0 check_circle_outline
question_answer
question_answer
question_answer
question_answer
How to delete the terminated intences in AWS Amazon?
Ans(2) ₹0 check_circle_outline
question_answer
Which is the best website to learn MongoDB online?
Ans(3) ₹0 check_circle_outline
question_answer
How many countries Twilio can send SMS?
Ans(2) ₹0 check_circle_outline
question_answer
question_answer
What is the maximum transaction limits in RazorPay?
Ans(1) ₹0 check_circle_outline
question_answer
PHP SDK - Delete Object not working on s3 - error \
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
Linux repeated Keyword problems.. how to solve it?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
How to create discount percentage using php?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
question_answer
check if the radio input is checked using javascript
Ans(1) ₹0 check_circle_outline
question_answer
PHP code to get the token of Shiprocket.
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
How to use webview on Android studio react native?
Ans(2) ₹0 check_circle_outline
question_answer
question_answer
What is SKU in shiprocket? From where I can get it?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
How to Propose Girls in this 2019?
Ans(2) ₹0 check_circle_outline
question_answer
How to Create Login and Logout system using PHP?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
How to integrate RazorPay with my website using PHP?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
1mb is equal to how much bytes?
Ans(1) ₹0 check_circle_outline
question_answer
How to delete projects from pinPoint on AWS?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
How to enable email functions on php?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
How to do Long poll using PHP and JavaScript?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
question_answer
How to open a file using Ubuntu Terminal?
Ans(2) ₹0 check_circle_outline
question_answer
question_answer
How to send sms using Terminal on AWS SNS?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
How to install PHP?
Ans(0) ₹0
question_answer
question_answer
question_answer
question_answer
How to write ourl url for SEO on href attribute
Ans(2) ₹0 check_circle_outline
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
What is the response time of PHP $post variable?
Ans(2) ₹0 check_circle_outline
question_answer
question_answer
question_answer
question_answer
question_answer
convert numbers into words in php
Ans(2) ₹0 check_circle_outline
question_answer
html css center horizontal list, menu system
Ans(2) ₹0 check_circle_outline
question_answer
question_answer
question_answer
Which is the most played sports in the world?
Ans(2) ₹0 check_circle_outline
question_answer
question_answer
Need PHP functions to convert currencies.
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
question_answer
What is the amount of withdrawn in RazorPay?
Ans(1) ₹0 check_circle_outline
question_answer
Need codes to see the Country using Cloudflare.
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
question_answer
question_answer
question_answer
Delete s3 object using PHP SDK.
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
Is RazorPay Really simple and esay to ues?
Ans(1) ₹0 check_circle_outline
question_answer
Multiple database vs single database on mysql?
Ans(1) ₹0 check_circle_outline
question_answer
Need codes to send SMS using AWS SNS in PHP.
Ans(1) ₹0 check_circle_outline
question_answer
.htaccess not working on my site .. what to do?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
question_answer
Is this PMEGP Loan works Offline also?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
question_answer
EDP Training Center in Kokrajhar area.
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
Which type of area is kown as Urban an Rural?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
The test asking
Ans(0) ₹0
question_answer
question_answer
Need ShipRocket support mobile number.
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
question_answer
Do Aliens really exists?
Ans(3) ₹0 check_circle_outline
question_answer
How pyshic powers work? Is it real or just rumors?
Ans(3) ₹0 check_circle_outline
question_answer
question_answer
question_answer
question_answer
Does girls like a man with a beard and mustache
Ans(2) ₹0 check_circle_outline
question_answer
PMEGP Loan Guide Lines.
Ans(1) ₹0 check_circle_outline
question_answer
What is La Liga?
Ans(1) ₹0 check_circle_outline
question_answer
Need official website links for PMEGP Loan.
Ans(1) ₹0 check_circle_outline
question_answer
multiple aws s3 bucket vs one aws s3 bucket?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
Can I create live straming videos using cloudfront?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
question_answer
question_answer
What is zend2?
Ans(0) ₹0
question_answer
How much tables one Mysql database can have?
Ans(1) ₹0 check_circle_outline
question_answer

WelCome to the World of Digital Expression

Transform your Works into Digital and Makes your life more easier.

123

Total users

123

Active users

5

Active Earners

location_on BTR,Assam,INDIA
(Bodoland)
email [email protected]
call +91 8486866741
rss_feed

Copyright ©2019-20 mritunjoy.com,All Rights Reserved