Deprecated: This repository has moved to https://glitch.com/edit/#!/stripe-example-mobile-backend.
For help with integrating the Stripe iOS and Android SDKs, including an example backend, visit our Accept a Payment guide.
A simple, easy-to-deploy backend that you can use to demo our example mobile apps.
License: MIT License
Deprecated: This repository has moved to https://glitch.com/edit/#!/stripe-example-mobile-backend.
For help with integrating the Stripe iOS and Android SDKs, including an example backend, visit our Accept a Payment guide.
Trying to deploy the example app on Heroku results in an error during the "Build app" step. This is the log:
-----> Ruby app detected
-----> Compiling Ruby/Rack
-----> Using Ruby version: ruby-2.5.0
-----> Installing dependencies using bundler 1.15.2
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.16.1). We suggest you upgrade to the latest version of Bundler by runninggem install bundler
.
Fetching gem metadata from https://rubygems.org/.......
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
Could not find multipart-post-2.0.0 in any of the sources
Bundler Output: Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.16.1). We suggest you upgrade to the latest version of Bundler by runninggem install bundler
.
Fetching gem metadata from https://rubygems.org/.......
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
Could not find multipart-post-2.0.0 in any of the sources
!
! Failed to install gems via Bundler.
!
! Push rejected, failed to compile Ruby app.
! Push failed>
Deploying on Heroku results in the following error:
Ruby ruby-2.5.3 is present on the following stacks:
Complete output:
-----> Building on the Heroku-20 stack
-----> Ruby app detected
-----> Installing bundler 1.17.3
-----> Removing BUNDLED WITH version in the Gemfile.lock
-----> Compiling Ruby/Rack
Command: 'set -o pipefail; curl -L --fail --retry 5 --retry-delay 1 --connect-timeout 3 --max-time 30 https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/heroku-20/ruby-2.5.3.tgz -s -o - | tar zxf - ' failed on attempt 1 of 3.
Command: 'set -o pipefail; curl -L --fail --retry 5 --retry-delay 1 --connect-timeout 3 --max-time 30 https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/heroku-20/ruby-2.5.3.tgz -s -o - | tar zxf - ' failed on attempt 2 of 3.
!
! The Ruby version you are trying to install does not exist on this stack.
!
! You are trying to install ruby-2.5.3 on heroku-20.
!
! Ruby ruby-2.5.3 is present on the following stacks:
!
! - cedar-14
! - heroku-16
! - heroku-18
!
! Heroku recommends you use the latest supported Ruby version listed here:
! https://devcenter.heroku.com/articles/ruby-support#supported-runtimes
!
! For more information on syntax for declaring a Ruby version see:
! https://devcenter.heroku.com/articles/ruby-versions
!
! Push rejected, failed to compile Ruby app.
! Push failed
I think the amount charged is hardcoded to 10.99 usd. I want to change the amount for the payment intent created I tried the below in my iOS app but it didn't work. any suggestions?
` func createPaymentIntent(completion: @escaping STPJSONResponseCompletionBlock) {
var url = URL(string: backendURL)!
url.appendPathComponent("create_payment_intent")
AF.request(url, method: .post, parameters: ["amount": 4000 , "currency" : "USD"])
.validate(statusCode: 200..<300)
.responseJSON { (response) in
switch (response.result){
case .failure(let error):
completion(nil, error)
case .success(let jsonResponse):
completion(jsonResponse as? [String : Any], nil)
}
}
}
`
The currency send to Strip server is hardcoded to "usd", whatever the client send in parameters.
line 53
:currency => "usd",
How to use the EphemeralKey create on laravel?
I am having the example backend constantly return error code 402. I have changed the variable from the example application from stripeToken to stripe_token and this passes as 200
Please only file issues here that you believe represent actual bugs in this demo code.
If you're having general trouble with your Stripe integration, please email [email protected] for a faster response.
For example, when /capture_payment
produces a 402
the puts
call in log_info
does not produce an entry in the Heroku logs.
I tried to add a config.ru
with the following contents (per this SO) but that did not work.
Here was my steps:
heroku git:clone -a ns-stripe-payment-intent
git clone [email protected]:stripe/example-ios-backend.git
cd example-ios-backend/ && cp -r * ../../ns-stripe-payment-intent/
cd ns-stripe-payment-intent
echo '$stdout.sync = true' > config.ru
git add . && git commit -am 'logging' && git push heroku master
Any ideas? I'm getting the following error when calling /capture_payment
from physical android device and trying to figure out why (works on android emulator, ios physical, ios emulator).
Error: The Source src_XXX does not belong to the Customer you supplied cus_YYY. Please use this Source with the Customer that it belongs to instead
Hi there,
I requested amount float number but It's always 400 bad request.
Please explain for me.
Thank you
It seems this repo stopped working with the latest Stripe releases. I'm testing it against the latest standard integration example. The heroku server returns 500 all the time for create_payment_intent endpoint. Any ideas?
Here are the logs:
2019-11-12T03:03:59.761288+00:00 app[web.1]: 2019-11-12 03:03:59 - TypeError - nil can't be coerced into Integer:
2019-11-12T03:03:59.761297+00:00 app[web.1]: web.rb:348:in `+'
2019-11-12T03:03:59.761300+00:00 app[web.1]: web.rb:348:in `block in calculate_price'
2019-11-12T03:03:59.761302+00:00 app[web.1]: web.rb:348:in `each'
2019-11-12T03:03:59.761304+00:00 app[web.1]: web.rb:348:in `reduce'
2019-11-12T03:03:59.761306+00:00 app[web.1]: web.rb:348:in `calculate_price'
2019-11-12T03:03:59.761309+00:00 app[web.1]: web.rb:213:in `block in <main>'
2019-11-12T03:03:59.761312+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1635:in `call'
2019-11-12T03:03:59.761314+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1635:in `block in compile!'
2019-11-12T03:03:59.761316+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:992:in `block (3 levels) in route!'
2019-11-12T03:03:59.761318+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1011:in `route_eval'
2019-11-12T03:03:59.761320+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:992:in `block (2 levels) in route!'
2019-11-12T03:03:59.761323+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1040:in `block in process_route'
2019-11-12T03:03:59.761325+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1038:in `catch'
2019-11-12T03:03:59.761327+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1038:in `process_route'
2019-11-12T03:03:59.761329+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:990:in `block in route!'
2019-11-12T03:03:59.761331+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:989:in `each'
2019-11-12T03:03:59.761333+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:989:in `route!'
2019-11-12T03:03:59.761335+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1097:in `block in dispatch!'
2019-11-12T03:03:59.761337+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1076:in `block in invoke'
2019-11-12T03:03:59.761339+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1076:in `catch'
2019-11-12T03:03:59.761341+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1076:in `invoke'
2019-11-12T03:03:59.761343+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1094:in `dispatch!'
2019-11-12T03:03:59.761344+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:924:in `block in call!'
2019-11-12T03:03:59.761346+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1076:in `block in invoke'
2019-11-12T03:03:59.761348+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1076:in `catch'
2019-11-12T03:03:59.761350+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1076:in `invoke'
2019-11-12T03:03:59.761352+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:924:in `call!'
2019-11-12T03:03:59.761354+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:913:in `call'
2019-11-12T03:03:59.761356+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/encrypted_cookie-0.0.5/lib/encrypted_cookie.rb:52:in `call'
2019-11-12T03:03:59.761358+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/rack-protection-2.0.5/lib/rack/protection/xss_header.rb:18:in `call'
2019-11-12T03:03:59.761360+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/rack-protection-2.0.5/lib/rack/protection/path_traversal.rb:16:in `call'
2019-11-12T03:03:59.761362+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/rack-protection-2.0.5/lib/rack/protection/json_csrf.rb:26:in `call'
2019-11-12T03:03:59.761364+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/rack-protection-2.0.5/lib/rack/protection/base.rb:50:in `call'
2019-11-12T03:03:59.761366+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/rack-protection-2.0.5/lib/rack/protection/base.rb:50:in `call'
2019-11-12T03:03:59.761368+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/rack-protection-2.0.5/lib/rack/protection/frame_options.rb:31:in `call'
2019-11-12T03:03:59.761370+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/rack-2.0.7/lib/rack/logger.rb:15:in `call'
2019-11-12T03:03:59.761372+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/rack-2.0.7/lib/rack/common_logger.rb:33:in `call'
2019-11-12T03:03:59.761374+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:231:in `call'
2019-11-12T03:03:59.761376+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:224:in `call'
2019-11-12T03:03:59.761377+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/rack-2.0.7/lib/rack/head.rb:12:in `call'
2019-11-12T03:03:59.761379+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/rack-2.0.7/lib/rack/method_override.rb:22:in `call'
2019-11-12T03:03:59.761381+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:194:in `call'
2019-11-12T03:03:59.761383+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1957:in `call'
2019-11-12T03:03:59.761385+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1502:in `block in call'
2019-11-12T03:03:59.761387+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1729:in `synchronize'
2019-11-12T03:03:59.761389+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.5/lib/sinatra/base.rb:1502:in `call'
2019-11-12T03:03:59.761391+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/rack-2.0.7/lib/rack/handler/webrick.rb:86:in `service'
2019-11-12T03:03:59.761393+00:00 app[web.1]: /app/vendor/ruby-2.5.3/lib/ruby/2.5.0/webrick/httpserver.rb:140:in `service'
2019-11-12T03:03:59.761403+00:00 app[web.1]: /app/vendor/ruby-2.5.3/lib/ruby/2.5.0/webrick/httpserver.rb:96:in `run'
2019-11-12T03:03:59.761405+00:00 app[web.1]: /app/vendor/ruby-2.5.3/lib/ruby/2.5.0/webrick/server.rb:307:in `block in start_thread'
2019-11-12T03:03:59.761788+00:00 app[web.1]: 98.234.84.197 - - [12/Nov/2019:03:03:59 +0000] "POST /create_payment_intent HTTP/1.1" 500
-----> Ruby app detected
-----> Compiling Ruby/Rack
!
! An error occurred while installing ruby-2.1.2
!
! Heroku recommends you use the latest supported Ruby version listed here:
! https://devcenter.heroku.com/articles/ruby-support#supported-runtimes
!
! For more information on syntax for declaring a Ruby version see:
! https://devcenter.heroku.com/articles/ruby-versions
!
! Note: Only the most recent version of Ruby 2.1 is supported on Cedar-14
!
! Debug InformationCommand: 'set -o pipefail; curl -L --fail --retry 5 --retry-delay 1 --connect-timeout 3 --max-time 30 https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/heroku-16/ruby-2.1.2.tgz -s -o - | tar zxf - ' failed unexpectedly:
!
! gzip: stdin: unexpected end of file
! tar: Child returned status 1
! tar: Error is not recoverable: exiting now
!
! Push rejected, failed to compile Ruby app.
! Push failed
I deployed this example backend to Heroku and running the "Basic Integration" iOS app from here: https://github.com/stripe/stripe-ios/tree/21.3.1
Getting this error:
Basic Integration[76811:9679837] Assertion failed: Could not parse the ephemeral key response following protocol STPCustomerEphemeralKeyProvider. Make sure your backend is sending the unmodified JSON of the ephemeral key to your app. For more info, see https://stripe.com/docs/mobile/ios/standard#prepare-your-api: file Stripe/STPEphemeralKeyManager.swift, line 136
Checking at the response with Charles Proxy, it is a 403 FORBIDDEN attempting to connect to this endpoint:
https://stripe-example-church.herokuapp.com/ephemeral_keys?api_version=2020-08-27
I am able to navigate to the heroku website from my browser and get the message "Great, your backend is set up. Now you can configure the Stripe example apps to point here."
Hello,
I had deployed example-ios-backend with heroku and working fine with stripe sample iOS app with standard integration.
While tried with custom integration "create_intent" API gives always error response 402.
Please let me know how can i test this.
Thanks in advance.
When I try to deploy to Heroku, I have this error : "could not find the source blob"
I have deployed the sample backend on heroku but when I charge I get an error 500 :
2018-06-11T08:39:43.833591+00:00 heroku[router]: at=info method=POST path="/charge" host=myapp.herokuapp.com request_id=f4b4e2b2-0000-1111-9999-e9542b146e2b fwd="XX.YYY.ZZ.00" dyno=web.1 connect=0ms service=716ms status=500 bytes=685 protocol=https
2018-06-11T08:39:43.834101+00:00 app[web.1]: 2018-06-11 08:39:43 - NoMethodError - undefined method indifferent_params for #Sinatra::Application:0x00000000023e0970:
2018-06-11T08:39:43.834111+00:00 app[web.1]: web.rb:45:in block in main
2018-06-11T08:39:43.834114+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:1634:in `call'
I have deployed as per the instructions. I have used custom stripe integration. /charge endpoint not working in both swift and objective C. But charge_card endpoint only working in objective C.
I have used STPAddCardViewController. The token is successfully generated.
let paymentURL = URLBuilder.chargeURL() //https://stripepaymentdemo.herokuapp.com/charge
print("payment url is \(paymentURL)")
//var urlRequest = URLRequest(url: paymentURL)
Alamofire.request(paymentURL, method: .post,
parameters: self.paymentInfo,
encoding: JSONEncoding.default, headers: [:]).validate().responseJSON { (response) in
switch(response.result) {
case .success(_):
if let data = response.result.value {
print(response.result.value ?? "data is nil")
self.completionHadler(data, nil)
}
break
case .failure(_):
print(response.result.error ?? "error is nil")
self.completionHadler(nil, response.result.error)
break
}
}
// Payment Info:
let params: [String: Any] = [
"stripe_token": token.tokenId ,
"amount": 4000
]
I'm trying to implement Stripe in my iOS app, but I have a hard time finding any backend examples that are live.
Specifically, I'm looking for an example that will let you:
Preferably in Rails (but any language at this point would do). Any pointers?
he problem: when using this method I simply clicked on the purple icon and proceeded to enter my info and created a backendUrl to be used for my app. All works except when it comes to processing the payment as my inventory items(located in firebase) are not able to be retrieved. Therefore, when placing order I get this in swift: "Failed to create a Payment Intent: unknown"
After getting this error I examined the logs in Heroku and came across this: RuntimeError - Can't find price for Guacamole
so it seems that the payment isn't going through because it can not retrieve the price for this item.
Finally I figure I just add "Guacamole" => 2000 to the list above and run it.
SADLY this did not work. I have no prior experience with ruby but when I applied the above to the list I still got the same error: RuntimeError - Can't find price for Guacamole
I did basically what you commented above but it is unable to retrieve prices for items I add to the EMOJI_StORE
am New to ruby etc just wonder if it’s possible for the backend to be passed a description for customer such as name and not have it hard coded and if it’s possi to automatically send a email receipt?
I'm using Stripe 2.4.0 and Sinatra 1.4.8 for playing with the iOS example (see https://github.com/stripe/stripe-ios).
When the route /customer/default_source
is invoked, I receive back the 402
error.
The sequence of calls is the following (using Charles Proxy):
/customer?
/customer/sources
/customer?
/customer/default_source
While call 2 returns the token tok_1AAKzxHeD6mKz6pSbhD6ZKtQ
, call 4 returns card_1AAKzxHeD6mKz6pSrY1VtDHH
.
Since they do not match, the error is returned back.
I've also noticed there is a mismatch between the documentation and the code provided. In particular, the documentation has the following code for routing the default_source
route:
require "json"
post "/customer/default_source" do
begin
customer_id = "..." # Load the Stripe Customer ID for your logged in user
customer = Stripe::Customer.retrieve(customer_id)
customer.default_source = params[:default_source]
customer.save
status 200
rescue Stripe::StripeError => e
status 402
return "Error retrieving customer: #{e.message}"
end
end
While the code in the example is:
post '/customer/default_source' do
authenticate!
source = params[:source]
# Sets the customer's default source
begin
@customer.default_source = source
@customer.save
rescue Stripe::StripeError => e
status 402
return "Error selecting default source: #{e.message}"
end
status 200
return "Successfully selected default source."
end
In the former params[:default_source]
is used while in the latter params[:source]
is adopted.
Any clue? Do I need to update the iOS Stripe lib? Using the code as is (with gem files dependencies in the Gemfile
) it works as expected.
Thanks, Lorenzo
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.