49336

Stripe payment with php

Question:

I am developing a website that is front end made with angularjs and backend with laravel. I want to integrate stripe payment. I am facing difficulty to add a angularjs api to laravel for stripe payment. So, I am trying to solve it with only procedural php. here is my code.

<?php require_once('/stripe-php/lib/Stripe.php'); require_once('/stripe-php/lib/Charge.php'); Stripe::setApiKey('my-secret-key'); $charge = Charge::create(array('amount' => 2000, 'currency' => 'usd', 'source' => $token )); if ($charge) { echo "Payment successcul"; } else { echo "Not success"; } ?>

I can get the token. But the payment is not processing and I see a blank page.

Answer1:

<strong>Follow this step to stripe payment.</strong> 1. download stripe folder from <a href="https://stripe.com/docs/libraries#php" rel="nofollow">https://stripe.com/docs/libraries#php</a> 2. Include the folder in your www folder in your project. 3. Make new PHP file and put this code into file.

<?php { require_once "./Stripe-php/init.php"; //include your stripe folder function __construct() { // put your keys here \Stripe\Stripe::setApiKey("Secret-Key"); } //put your code into function. $token = $_POST['stripeToken']; // Token ID $charge = \Stripe\Charge::create([ 'amount' => $20 * 100, 'currency' => 'usd', 'description' => 'Message', 'source' => $token, ]); if($charge['status'] == "succeeded"){ // if success $status=1; $post['charge_id']=$charge['id']; $post['amount']=$charge['amount']; $post['funding']=$charge['source']['funding']; $post['holder_name']=$charge['source']['name']; $post['brand']=$charge['source']['brand']; $Message="Payment Success"; } else{ $status=2; // failed $post=null; $Message="Payment Failed"; } $data["status"] = ($status > 1) ? FAILED : SUCCESS; $data["message"]=$Message; $data["PaymentData"]=$post; return $data; // JSON Returen } ?>

Answer2:

Include <a href="https://stripe.com/docs/api#error_handling" rel="nofollow">Stripes error handling</a> in the page itself.

try { // Use Stripe's library to make requests... } catch(\Stripe\Error\Card $e) { // Since it's a decline, \Stripe\Error\Card will be caught $body = $e->getJsonBody(); $err = $body['error']; print('Status is:' . $e->getHttpStatus() . "\n"); print('Type is:' . $err['type'] . "\n"); print('Code is:' . $err['code'] . "\n"); // param is '' in this case print('Param is:' . $err['param'] . "\n"); print('Message is:' . $err['message'] . "\n"); } catch (\Stripe\Error\RateLimit $e) { // Too many requests made to the API too quickly } catch (\Stripe\Error\InvalidRequest $e) { // Invalid parameters were supplied to Stripe's API } catch (\Stripe\Error\Authentication $e) { // Authentication with Stripe's API failed // (maybe you changed API keys recently) } catch (\Stripe\Error\ApiConnection $e) { // Network communication with Stripe failed } catch (\Stripe\Error\Base $e) { // Display a very generic error to the user, and maybe send // yourself an email } catch (Exception $e) { // Something else happened, completely unrelated to Stripe }

Recommend

  • Paypal Parallel Payment with Multiple Currencies
  • App crashing when buying in-app purchase
  • Relationship between orders, customers and products?
  • is paypal's iphone sdk for payment approved by apple? [closed]
  • Why Is jQuery Not Submitting This Form? (Or What Have I Done Wrong? :-p)
  • Send money from Braintree
  • Eloquent Relationship on Partial Match
  • include dlls in visual studio c++ 2008
  • react split panel resize
  • Can you pass an array from javascript to asp.net mvc controller action without using a form?
  • C++ Single function pointer for all template instances
  • Can I have a variable number of URI parameters or key-value pairs in Laravel 4?
  • Redirect to Post Method/Action
  • Debugging VB6 Code From Visual Studio 2010
  • saving file generated by TCPDF
  • Diff between two dataframes in pandas
  • Zurb Foundation _global.scss meta styles for js?
  • why xml file does not aligned properly after append the string in beginning and end of the file usin
  • htaccess add www if not subdomain, if subdomain remove www
  • How to run “Deployd” on port 80 instead of port 5000 in webserver.
  • Content-Length header not returned from Pylons response
  • JSON response opens as a file, but I can't access it with JavaScript
  • Test if a set exists before trying to drop it
  • MailKit: The IMAP server replied to the 'EXAMINE' command with a 'BAD' response
  • Python urlparse: small issue
  • Django: Count of Group Elements
  • Paperclip, set path outside of rails root folder
  • RectangularRangeIndicator format like triangular using dojo
  • Accessing IRQ description array within a module and displaying action names
  • How to add a column to a Pandas dataframe made of arrays of the n-preceding values of another column
  • Cross-Platform Protobuf Serialization
  • Can I make an Android app that runs a web view in Chrome 39?
  • Timeout for blocking function call, i.e., how to stop waiting for user input after X seconds?
  • QuartzCore.framework for Mono Develop
  • RestKit - RKRequestDelegate does not exist
  • Revoking OAuth Access Token Results in 404 Not Found
  • Proper folder structure for lots of source files
  • Load html files in TinyMce
  • Append folder name and increment by 1 using batch script
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass