Coder Social home page Coder Social logo

stripe-archive / accept-a-card-payment Goto Github PK

View Code? Open in Web Editor NEW
352.0 352.0 296.0 974 KB

Learn how to accept a basic card payment on web, iOS, Android

Home Page: https://stripe.com/docs/payments/accept-a-payment

License: MIT License

Java 16.58% Kotlin 9.45% Objective-C 9.02% Swift 7.28% Ruby 7.93% CSS 15.26% HTML 3.44% JavaScript 14.38% PHP 7.91% Python 3.90% TypeScript 4.67% Shell 0.16%
card-payment stripe

accept-a-card-payment's Introduction

This project is deprecated and is no longer being actively maintained.

Please see the Accept a payment sample.

Accepting a card payment

Cards are one of the most popular ways to pay online. Stripe offers several ways to accept card payments, depending on your business needs.

If you accept cards in regions like Europe and India, you will need to handle requests from banks to authenticate a purchase (commonly known as 3DS or OTP) and can choose between our using-webhooks and without-webhooks integrations.

If you only accept cards from U.S. and Canadian customers, you can use our integration that declines any bank requests for authentication but is much easier to integrate.

Read more about cards on Stripe in our docs.

Using webhooks Without webhooks Declining on card authentication
Recommended for Businesses with a global customer base who want to add other payment methods Businesses with a global customer base who only want to accept cards and don't want to use webhooks Businesses who only have customers in the U.S. & Canada
Bank authentication requests Automatically handles, no need for extra code Requires extra code to handle authentication Declines any payments that require authentication
Payment flow Server -> Client Client -> Server -> Client -> Server Client -> Server
Webhooks for post-payment fulfillment Recommended (scales better to future payment method) Optional Optional

Demo

Web: See a hosted version of the sample or fork a copy on codesandbox.io

Mobile: Run the sample locally

All the samples run in test mode -- use the below test card numbers with any CVC code + a future expiration date to test for certain behavior.

Test card number Using webhooks Without webhooks Declining on card authentication
4242424242424242 Succeeds Succeeds Succeeds
4000000000003220 Displays a pop-up modal to authenticate Displays a pop-up modal to authenticate Declines and asks customer for new card

Read more about testing on Stripe at https://stripe.com/docs/testing.

Accepting a card payment

How to run locally

This sample includes several implementations of the same server in Node, Node Typescript, Ruby, Python, Java, PHP, and PHP (Slim) for the two integration types: using-webhooks and without-webhooks.

Follow the steps below to run locally.

1. Clone and configure the sample

The Stripe CLI is the fastest way to clone and configure a sample to run locally.

Using the Stripe CLI

If you haven't already installed the CLI, follow the installation steps in the project README. The CLI is useful for cloning samples and locally testing webhooks and Stripe integrations.

In your terminal shell, run the Stripe CLI command to clone the sample:

stripe samples create accept-a-card-payment

The CLI will walk you through picking your integration type, server and client languages, and configuring your .env config file with your Stripe API keys.

Installing and cloning manually

If you do not want to use the Stripe CLI, you can manually clone and configure the sample yourself:

git clone https://github.com/stripe-samples/accept-a-card-payment

Copy the .env.example file into a file named .env in the folder of the server you want to use. For example:

cp .env.example using-webhooks/server/node/.env

You will need a Stripe account in order to run the demo. Once you set up your account, go to the Stripe developer dashboard to find your API keys.

STRIPE_PUBLISHABLE_KEY=<replace-with-your-publishable-key>
STRIPE_SECRET_KEY=<replace-with-your-secret-key>

STATIC_DIR tells the server where the client files are located and does not need to be modified unless you move the server files.

2. Follow the server instructions on how to run:

Pick the server language you want and follow the instructions in the server folder README on how to run.

For example, if you want to run the Node server in using-webhooks:

cd using-webhooks/server/node # there's a README in this folder with instructions
npm install
npm start

3. [Optional] Run a webhook locally:

If you want to test the using-webhooks integration with a local webhook on your machine, you can use the Stripe CLI to easily spin one up.

First install the CLI and link your Stripe account.

stripe listen --forward-to localhost:4242/webhook

The CLI will print a webhook secret key to the console. Set STRIPE_WEBHOOK_SECRET to this value in your .env file.

You should see events logged in the console where the CLI is running.

When you are ready to create a live webhook endpoint, follow our guide in the docs on configuring a webhook endpoint in the dashboard.

4. [Mobile clients] Set up the client app:

Finally, choose a mobile client implementation and follow the instruction in the README to run:

When the app is running, use 4242424242424242 as a test card number with any CVC code + a future expiration date.

Use the 4000000000003220 test card number to trigger a 3D Secure challenge flow.

Read more about testing on Stripe at https://stripe.com/docs/testing.

FAQ

Q: Why did you pick these frameworks?

A: We chose the most minimal framework to convey the key Stripe calls and concepts you need to understand. These demos are meant as an educational tool that helps you roadmap how to integrate Stripe within your own system independent of the framework.

Get support

If you found a bug or want to suggest a new [feature/use case/sample], please file an issue.

If you have questions, comments, or need help with code, we're here to help:

Sign up to stay updated with developer news.

Author(s)

@adreyfus-stripe @bg-stripe @yuki-stripe @thorsten-stripe

accept-a-card-payment's People

Contributors

adreyfus-stripe avatar auchenberg-stripe avatar brendanm-stripe avatar ccen-stripe avatar ch-stripe avatar cjavilla-stripe avatar ctrudeau-stripe avatar davidme-stripe avatar dawn-stripe avatar dependabot[bot] avatar ecarlson2020 avatar hibariya avatar kristiehuang avatar kunal-mandalia avatar mshafrir-stripe avatar qaisjp-stripe avatar rimiti avatar thorsten-stripe avatar trag-stripe avatar vcheung-stripe avatar yuki-stripe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

accept-a-card-payment's Issues

without webhooks php, notice interrupt payment process

Bug report

Notice: Undefined property: stdClass::$paymentMethodId

Describe the bug

I am using 3d secure card for completing payment. After clicking on complete button in popup this shows a notice:-
Undefined property: stdClass::$paymentMethodId in pay.php file with line if($body->paymentMethodId != null)

Display bug

Hi,
I have this display bug when I test this sample :
accept-a-card-payment/using-webhooks/server/php/public/

image

I ran this example locally and with firefox 74.0.1
Everything seems to works well except this display.
Can you help me please ? Thank you,

"without-webhooks/server/php/public" does not work InternetExplorer11

Bug report

Describe the bug

I'm testing the "without-webhooks/server/php/public" sample with Internet Explorer 11.
However, the page is not displayed well in Internet Explorer 11.
In addition, it has been confirmed that it can be used normally with Firefox and Chrome.
How can I make it available on Internet Explorer11?

To Reproduce

  1. Open a command prompt and execute the following command.
cd without-webhooks/server/php/public
php -S 127.0.0.1:4242
  1. Open InternetExplorer11 and access "http://localhost:4242".
  2. The input form for credit card information is not displayed, only the "Pay" button is displayed.

Expected behavior

An input form for credit card information is displayed, and payment is completed normally.

System information

  • OS: Windows10 2004 64Bit build 19041.388
  • Browser: InternetExplorer11 Version 11.388.19041.0
  • Server environment: PHP7.4

go file

Bug report

Describe the bug

A clear and concise description of what the bug is.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: [e.g. macOS, Windows]
  • Browser (if applies) [e.g. chrome, safari]
  • Server environment [e.g. Go, Java, Node, PHP, Python, Ruby, TypeScript]

Additional context

Add any other context about the problem here.

Declined payment without webhook server php not working

Good morning,
I'm integrating the solution server PHP without webhook but there's something wrong with the declined payments (e.g. using 4000 0000 0000 9995).

The browser debug is giving me these 2 feedback:

  1. POST 500 > script.js line 101
  2. Uncaught (in promise) SyntaxError: Unexpected end of JSON input > script.js line 111

Actually I also found a small typing error at line 64 in script.js and I solved it.
It has to be pay.php instead of /pay

Successful payments are working properly, including the ones with authentication.
The problem I have it seems to be related only to declined payments.

Thank you for the kind support and for the very useful library!
Best regards.

How can I delete postal code from input?

Bug report

Describe the bug

A clear and concise description of what the bug is.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: [e.g. macOS, Windows]
  • Browser (if applies) [e.g. chrome, safari]
  • Server environment [e.g. Go, Java, Node, PHP, Python, Ruby, TypeScript]

Additional context

Add any other context about the problem here.

iOS object-C target run error

Bug report

iOS object-C target run error

Describe the bug

When I download the project from github, it reports an error directly after running pod install, because it is cocoapods installation that I can’t change the code, please tell me how to solve this problem
A clear and concise description of what the bug is.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Go to 'Stripe Example App '
  2. Click on 'Stripe Example App object target'
  3. run target
  4. See error

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

image

If applicable, add screenshots to help explain your problem.

System information

  • OS:macOS10.15.6 [e.g. macOS, Windows]

Additional context

Add any other context about the problem here.

Stripe

Bug report

Describe the bug

A clear and concise description of what the bug is.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: [e.g. macOS, Windows]
  • Browser (if applies) [e.g. chrome, safari]
  • Server environment [e.g. Go, Java, Node, PHP, Python, Ruby, TypeScript]

Additional context

Add any other context about the problem here.

Not compatible with iOS 13 dark mode

If you enable 'dark mode' on iOS 13 then all of the input text will become invisible.

When you first launch the app some of the text is visible, but when you tap into the text field and try to enter text it will be invisible.

PaymentIntent not found when paying

PaymentIntent not found when submitting payment. Error: "PaymentIntent hasn't been created".
Using iOS Objective-C client and Node (using webhook).

node implementation not working

The node implementation in the without hooks code set is not working.

To get it working the following needs to be added near the top of server.js

var bodyParser = require('body-parser');
app.use(bodyParser.json());

Ft

Bug report

Describe the bug

A clear and concise description of what the bug is.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: [e.g. macOS, Windows]
  • Browser (if applies) [e.g. chrome, safari]
  • Server environment [e.g. Go, Java, Node, PHP, Python, Ruby, TypeScript]

Additional context

Add any other context about the problem here.

Please help me for stripe integration in angular 7

I can't push amount value for payment to stripe in my angular js project.

Code is below here::

<button (click)="pay('{{milestone.milestone_value}}')" class="btn btn-primary btn-block">Pay {{milestone.milestone_value | currency: '$' }}

Please help me to set the amount into "pay(???)"

Thanks in advance.

Android gson.fromjson() expected BEGIN_OBJECT but was STRING at line 1 column 1 path $

Hi, there, I am using the android as client and php as server.
The php = 7.2, stripe/stripe-php = 7.0.
The response json is generated by the following php code sample.
$output = [ 'publishableKey' => $config['stripe_publishable_key'], 'clientSecret' => $paymentIntent->client_secret, ]; echo json_encode($output);
When I pass the json string from server side to the gson.fromjson() at client side, it outputs the error 'expected BEGIN_OBJECT but was STRING at line 1 column 1 path $'.
What I found is that a 'POST' keyword is added at the beginning of json string, which caused the parsing failure of gson. The gson seems to expect something like {\json_content}. But now it gets POST{\json_content}.
I am confused about the reason why the 'POST' is added. Is there any way to solve this problem?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.