How to quickly connect to the Stripe international payment system

Introduction to Stripe International Payments

> Stripe was founded by brothers Patrick Collison and John Collison in their 20s to provide online payment solutions for companies. Stripe charges 2.9 percent of each transaction plus a 30-cent processing fee to the companies it serves.

Many Chinese sellers want to use Stripe to build a website and collect payments. Stripe is now called "PayPal in the mobile era". The customers currently served include well-known companies such as Facebook, Twitter, Shopify, Kickstarter, Target, Wish, Digitalocean, Pinterest, Docker, and Sap. Stripe also has a large number of individual small and medium-sized customers and merchants. More than 100,000 companies around the world have Using Stripe's services, the platform's annual transaction volume has exceeded $1 billion. Stripe has developed rapidly in recent years, and its share in foreign markets is quite high. Stripe offers easy-to-see, easy-to-use payment methods, simple design, easy-to-use, in-site payments, and everything you need to create a fast and efficient mobile commerce experience.

Introducing Stripe

Stripe focuses on solving the problem of online merchant payment. Stripe's products cover all aspects of online merchant payment. At present, it is divided into three major products (Payments, Subscription, Connect) and three small products (Sigma, Atlas, Radar)

Payments

Payments is Stripe's first and most basic product. Payments provides APIs and toolkits that allow developers to develop their own payment flow. Payments accepts credit cards and common network payment methods (ACH debits, bitcoin, alipay, WeChat Pay), and by providing the client with a PCI-DSS-compliant token, sensitive information will not pass through the client's server (exemption). Stripe is committed to simplifying developers' troubles, integrating Payments as fast as one line of javascript code (including UI).

Subscription

The problem that Subscription solves is how to efficiently handle recurring billing. Stripe identified many pain points in periodic billing processing and provided an all-in-one solution. Subscription can automatically calculate the refund amount after cancellation in the cycle, and supports trial periods and usage-based plans. For enterprise users, a per-seat (basic price + user fee * user quantity) pricing scheme can be supported. Another pain point of periodic payment is the expiration of the credit card. Subscription can automatically update the new card information after the old card expires by working with the credit card network, thereby avoiding the payment failure due to the expiration of the credit card.

Connect

The target group of Connect services is marketplace or platform (similar to Taobao, ebay, eventtribe). The payment requirements of such platforms are to link buyers and sellers, including one-to-one (such as uber), one-to-many (such as one order on Taobao from different merchants), and many-to-many (such as Google Play provides all users HBO, Additional services such as ShowTime), temporary storage of funds (for example, payment occurs after the concert, similar to the role of Alipay). Paying on the US platform will involve tax and legal issues. Connect will notify the platform to carry out the corresponding legal procedures when the amount received by some users exceeds a certain threshold.

Sigma

Sigma is a data analysis product provided by the user based on all existing information on Stripe. Through Sigma users (enterprises) do not need to build complex pipelines to analyze their own payment data, but directly conduct complex data analysis through Stripe's own web UI and SQL statements to make business decisions quickly and accurately.

Atlas

To help more people build companies quickly, Atlas takes responsibility for all the steps of building a company at once. After registering for Atlas and submitting a one-time fee, Stripe will register an incorporation in Delaware for you within a week, open a commercial bank account with Silicon Valley Bank, and provide a free legal service, plus additional legal and tax services. Through the previous acquisition of Indie Hackers, Atlas also provides an entrepreneurial community to help users who start a business get started quickly

Radar

A set of self-developed risk control engine system to help enterprises avoid risks.

Integrate Stripe Payments

Before integrating Stripe's payment, we need to understand Stripe's management platform.

  1. Registration management platform, test environment registration address
  2. After success, the management platform will generate a secret key for us
  3. Bring this key when you request, then the money will be transferred to your registered management platform account
  4. By binding the card on the management platform, you can perform operations such as withdrawals

After successful registration, we can see the management page as shown below, we can see our secret key, as well as the flow of funds and so on.

We choose one of the simplest integration methods, which is to integrate Stripe's Chekcout page, which only requires a few lines of code to integrate Stripe's payment capabilities. The approximate process is represented by a sequence diagram, as shown below:

The CheckOut page is the one provided by Stripe and we don't need to change it. The page looks like this.

Don't talk nonsense and go directly to the code. I use Java for integration. The code for generating Session is as follows

@GetMapping("/pay")
@ResponseBody
public Map<string,string>  pay(HttpServletRequest httpRequest, HttpServletResponse httpResponse){
    Map<string,string> resultMap = new HashMap&lt;&gt;();
    try {
        Stripe.apiKey = privateKey;
        Map<string, object> params = new HashMap<string, object>();
        ArrayList<string> paymentMethodTypes = new ArrayList&lt;&gt;();
        paymentMethodTypes.add("card");
        params.put("payment_method_types", paymentMethodTypes);
        ArrayList<hashmap<string, object>&gt; lineItems = new ArrayList&lt;&gt;();
        HashMap<string, object> lineItem = new HashMap<string, object>();
        lineItem.put("name", "胡鹏飞测试商品");
        lineItem.put("description", "这是一个测试单描述");
        lineItem.put("amount", 500); // 支付金额
        lineItem.put("currency", "usd"); //支付币种
        lineItem.put("quantity", 1);
        lineItems.add(lineItem);
        params.put("line_items", lineItems);
        //TODO 必须使用https 返回的回调地址
        String uuid = UUID.randomUUID().toString();
        params.put("client_reference_id", uuid);//业务系统唯一标识 即订单唯一编号
        log.info("uuid:{}",uuid);
        params.put("success_url", URLUtils.getBaseURl(httpRequest)+"/paySuccess");// 支付成功跳转页面
        params.put("cancel_url",  URLUtils.getBaseURl(httpRequest)+"/payError");// 支付失败跳转页面
        Session session = Session.create(params);
        String sessionId = session.getId();
        log.info("sessionId :{}",session.getId());
        resultMap.put("sessionId",sessionId);
    } catch (StripeException e) {
        e.printStackTrace();
    }
    return resultMap;
}

Among them, I did not let the front end to pass the business information, I wrote it in the background, just for the convenience of calling. You can see that the generated sessionId is passed to the front end, and then the front end makes the following calls. You can directly jump to the checkOut page for payment.

stripe.redirectToCheckout({
    sessionId: data.sessionId
}).then(function (result) {
    console.log(result);
});

So far, we have integrated Stripe's payment function with these few lines of code. In fact, Stripe supports many more functions. As we introduced above, it also supports subscription payment. Of course, we can also not use its checkout page, but Our custom page is just a little troublesome, so I won't introduce it here. If you need it, you can check its documentation for details. The relevant documents are listed below.

In the GitHub code, there is also information about interfaces such as refunds and callbacks. I will not introduce them one by one here. You can go to github and pull down the code to check it out.

code address

Relevant information

{{o.name}}
{{m.name}}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324123788&siteId=291194637