<form id="dlljd"></form>
        <address id="dlljd"><address id="dlljd"><listing id="dlljd"></listing></address></address>

        <em id="dlljd"><form id="dlljd"></form></em>

          <address id="dlljd"></address>
            <noframes id="dlljd">

              聯系我們 - 廣告服務 - 聯系電話:
              您的當前位置: > 關注 > > 正文

              全球今頭條!【Stripe支付】國際版APP、Braine注冊流程詳解

              來源:CSDN 時間:2023-03-15 15:25:45

              文章目錄

              一、了解Stripe支付二、Stripe注冊流程三、Stripe API 特點3.1 Apikey3.2 Idempotent Requests 冪等請求3.3 兩種付款方式 四、Stripe 支付核心API4.1 Token4.2 Customer4.3 Card4.4 Source4.5 charge4.6 PaymentIntents4.7 PaymentMethod 五、完整Stripe支付代碼


              (相關資料圖)

              一、了解Stripe支付

              最近公司正在做一個國際版APP,涉及到海外支付,調研過Paypal、Skrill、BrainTree、Stripe(可參考海外移動支付方案對比),最終 選擇了Stripe支付。Stripe特點如下:

              收費規則簡單透明,手續費就是收取訂單總額的3.4 % + HK$2.35。沒有月費、開戶費、退款手續費,撤銷付款費用手續費HK$85.00Stripe支持135+種貨幣創建付款(目前不支持中國大陸,只支持中國香港)。Stripe還支持其他付款方式,包括ACH信用轉賬、ACH借記轉賬、支付寶、Android Pay、Apple Pay、Bancontact、Bitcoin(比特幣)、銀行卡(Visa,Mastercard,American Express,Discover,Diners Club,JCB等)、Giropay、iDEAL、SEPA、SOFORT、微信支付等來自全球的熱門支付方式。Stripe的開發文檔清晰簡單,集成友好。提供了IOS、Android的SDK,以及對各種語言的支持。

              二、Stripe注冊流程

              和其他國內支付平臺一樣,首先需要注冊Stripe賬戶。官網注冊鏈接: 在注冊頁面中填寫郵箱信息完成注冊即可。進入了DashBoard,可以看到賬戶還沒有被激活,在激活賬戶之前先驗證電子郵件,然后點擊激活賬號:

              賬戶激活的時候,因為Stripe不支持中國,所以要用支持的國家注冊商戶,而你恰恰有這個國家的公司信息、銀行卡信息之類的,最后一定要發送手機號碼驗證,要不然在調用API的時候,會報錯,提示你沒有完善信息。 我這是公司賬號,使用公司在香港信息完成了賬戶激活??梢钥吹?,出現了API 密鑰的內容提示,說明我們完成激活,可以開始玩了。

              三、Stripe API 特點

              3.1 Apikey

              Stripe.apiKey = "sk_test_*****************************";

              Stripe API使用API密鑰來驗證請求,在控制臺有兩種密鑰:測試密鑰和生產密鑰

              在調用每個API的時候,要在每個請求中發送此密鑰。

              3.2 Idempotent Requests 冪等請求

              Stripe API 支持Idempotentcy 來安全的重試請求,而不會意外的執行兩次相同的操作。冪等性密鑰是客戶端生成的唯一值,服務器使用該值來識別同一個請求的重試。

              3.3 兩種付款方式

              Stripe 現在提供兩種方式的支付API:Payment Methods API 和 Tokens and SourcesAPIs

              兩者的區別在于Sources是通過status屬性描述事物狀態的。這意味著每個Source對象必須先轉換為可收費狀態才能用于付款,相反Payment Methods 是無狀態的,依賴于PaymentIntent對象來表示給定支付的交易狀態

              如圖所示,官方建議遷移到Payment Methods API

              四、Stripe 支付核心API

              Stripe 本身提供了大而全的東西,其核心的API,包括以下模塊: 官網給出了一個支付過程的說明,只需要六步就能完成操作,收集Card信息、創建用戶、支付、計劃、訂閱,完成支付,基本上第四部和第五步,我們不會使用。簡單易上手。

              我們自身業務關心的是Payment這塊,所以核心的API也是集中在Payment這塊兒說明,包括Token、Card、Customer、PaymentIntent、PaymentMethod、Source、Charge等,我們都使用創建API來挨個來了解一下。

              4.1 Token

              Token是Stripe用來客戶收集敏感卡或者銀行賬戶信息的過程,當用戶填寫了銀行卡的卡號、過期年月、CVC等信息后,Stripe會生成過一個包含這些信息的Token,這樣在傳輸過程中,確保沒有敏感的卡數據和我們自己的服務器交互,降低客戶真實信息丟失率。我們自身的服務器,取到token,進行支付即可 。

              Token不能多次存儲和使用,要存儲卡的信息供以后使用,可以創建用戶。將卡的信息添加給用戶。

              #創建Token    Stripe.apiKey = "sk_test_your_key";    MaptokenParams = new HashMap();    MapcardParams = new HashMap();    cardParams.put("number", "4242424242424242");    cardParams.put("exp_month", 8);    cardParams.put("exp_year", 2020);    cardParams.put("cvc", "314");    tokenParams.put("card", cardParams);    Token.create(tokenParams);

              4.2 Customer

              Customer 允許執行與同一客戶關聯的重復費用,并跟蹤多個費用。可以創建、刪除和更新客戶。也可以檢索單個客戶以及所有客戶的列表。

              MapcustomerParams = new HashMap();                customerParams.put("description", "Customer for chao");        customerParams.put("source", "tok_**********");        Customer c = null;        try {            c = Customer.create(customerParams);            System.out.println(c);        } catch (StripeException e) {            e.printStackTrace();        }

              4.3 Card

              可以在一個客戶上存儲多張卡,向該客戶收費。

              Stripe.apiKey = "your_apikey";      Customer customer = Customer.retrieve("cus_FfoCbKMV4SJ7je");      Mapparams = new HashMap();      params.put("source", "tok_mastercard");      customer.getSources().create(params);

              4.4 Source

              Source代表接收各種付款方式,代表客戶的支付工具。創建收費的時候,可以附加到客戶。

              Stripe.apiKey = "sk_test_1crNbJbtW30srR0CxeJHtFNF003Cuo2uSJ";MapsourceParams = new HashMap();sourceParams.put("type", "ach_credit_transfer");sourceParams.put("currency", "usd");MapownerParams = new HashMap();ownerParams.put("email", "jenny.rosen@example.com");sourceParams.put("owner", ownerParams);Source.create(sourceParams);

              4.5 charge

              對信用卡或者借記卡收費時,創建一個charge對象

              Stripe.apiKey = "your_apikey";MapchargeParams = new HashMap();chargeParams.put("amount", 2000);chargeParams.put("currency", "hkd");chargeParams.put("description", "Charge for jenny.rosen@example.com");chargeParams.put("source", "tok_mastercard");Charge.create(chargeParams);

              4.6 PaymentIntents

              PaymentIntents 將指導你完成從客戶處收款的過程,官方建議為系統中的每一個訂單或者客戶創建一個PaymentIntent。

              Stripe.apiKey = "your_alikey";MappaymentIntentParams = new HashMap<>();paymentIntentParams.put("amount", 2000);paymentIntentParams.put("currency", "hkd");ArrayListpaymentMethodTypes = new ArrayList<>();paymentMethodTypes.add("card");paymentIntentParams.put("payment_method_types", paymentMethodTypes);PaymentIntent.create(paymentIntentParams);

              4.7 PaymentMethod

              PaymentMethod代表客戶的支付工具,和PaymentIntents一起使用 以收取付款或保存到客戶對象。

              Stripe.apiKey = "your_alikey";MappaymentmethodParams = new HashMap();paymentmethodParams.put("type", "card");MapcardParams = new HashMap();cardParams.put("number", "4242424242424242");cardParams.put("exp_month", 8);cardParams.put("exp_year", 2020);cardParams.put("cvc", "314");paymentmethodParams.put("card", cardParams);PaymentMethod.create(paymentmethodParams);

              五、完整Stripe支付代碼

              網上看了一大圈關于Stripe的支付,資料很少,要么是年代久遠,要么是代碼不完整。希望我的代碼對你有所用。

              我們的前端業務流程如圖所示: 選擇的支付方式是Token and Source API,控制器類StripeController 代碼如下:

              @Controller@RequestMapping(value = "/stripe")public class StripeController {    @Resource    private StripePayService stripePayService;     private static Logger logger = LoggerFactory.getLogger(StripeController.class);    /**     * 獲取用戶卡片列表     *     * @return     */    @RequestMapping(value = "/getCardList", method = RequestMethod.POST)    @ResponseBody    public Response getCardList(@RequestBody @Valid StripePayRequestVO stripePayRequestVO, BindingResult result) {               return stripePayService.getCardList(stripePayRequestVO);    }     /**     * 添加用戶卡片     * @return     */    @RequestMapping(value = "/addCard", method = RequestMethod.POST)    @ResponseBody    public Response addCard(@RequestBody @Valid StripePayRequestVO stripePayRequestVO, BindingResult result) {        logger.debug("購買套餐請求參數 {} = ", JsonUtil.INSTANCE.toJson(stripePayRequestVO));        return stripePayService.addCard(stripePayRequestVO);    }    /**     * 發起支付     * @return     */    @RequestMapping(value = "/charge", method = RequestMethod.POST)    @ResponseBody    public Response aliPay(@RequestBody @Valid StripePayRequestVO stripePayRequestVO, BindingResult result) {        return stripePayService.charge(stripePayRequestVO);    }}

              DAO層

              public interface StripePayService {    Response charge(StripePayRequestVO stripePayRequestVO);    Response getCardList(StripePayRequestVO stripePayRequestVO);    Response addCard(StripePayRequestVO stripePayRequestVO);}

              實現層

              @Service("stripePayService")public class StripePayServiceImpl implements StripePayService {    @Override    public Response charge(StripePayRequestVO request) {        try {            Stripe.apiKey = "your_apikey";            Mapparams = new HashMap();            params.put("userId", request.getUserId());            User user = this.get("from User where id=:userId", params);            if (null == user) {                return failure(ResponseEnum.USER_NOT_FOUND_FAILURE);            }            //無stripe賬號,直接返回            if (user.getStripeChargeId() == null || "".equals(user.getStripeChargeId())) {                return success(ResponseEnum.USER_BAD_REQUEST_FAILURE);            }                      // 業務訂單數據,此處省略                //發起支付            MappayParams = new HashMap<>();            payParams.put("amount", product.getPrice().intValue());            payParams.put("currency", "usd");            payParams.put("description", "Charge for " + user.getEmail());            payParams.put("customer", user.getStripeChargeId());            Charge charge = Charge.create(payParams);               //charge  支付是同步通知            if ("succeeded".equals(charge.getStatus())) {                //交易成功后,需要更新我們的訂單表,修改業務參數,此處省略                return success(ResponseEnum.PAY_SUCCESS.getMessage());            } else {                return failure(ResponseEnum.PAY_ALIPAY_FAILURE);            }        } catch (StripeException e) {            e.printStackTrace();        }        return failure(ResponseEnum.EVENT_SYSTEM_ERROR_FAILURE);    }    @Override    public Response getCardList(StripePayRequestVO stripePayRequestVO) {        Stripe.apiKey = "your_alipay";        Mapparams = new HashMap();        params.put("userId", stripePayRequestVO.getUserId());        User user = this.get("from User where id=:userId", params);        if (null == user) {            return failure(ResponseEnum.USER_NOT_FOUND_FAILURE);        }        List list = new ArrayList();        //如果沒有這個stripe用戶,就返回列表為空                    try {                MapcardParams = new HashMap();                cardParams.put("limit", 1);                cardParams.put("object", "card");                ListcardList = Customer.retrieve(user.getStripeChargeId()).getSources().list(cardParams).getData();                StripeCardVO stripeCardVO = new StripeCardVO();                for (PaymentSource p : cardList) {                    Card c = (Card) p;                    stripeCardVO.setLast4(c.getLast4());                    stripeCardVO.setExpYear(c.getExpYear());                    stripeCardVO.setExpMonth(c.getExpMonth());                    list.add(stripeCardVO);                }                return success(list);            } catch (StripeException e) {                e.printStackTrace();            }    }    @Override    public Response addCard(StripePayRequestVO stripePayRequestVO) {        Stripe.apiKey = "your_alipay";        Mapparams = new HashMap();        params.put("userId", stripePayRequestVO.getUserId());        User user = this.get("from User where id=:userId", params);        if (null == user) {            return failure(ResponseEnum.USER_NOT_FOUND_FAILURE);        }        //如果沒有這個stripe用戶,添加卡片就是創建用戶        if (user.getStripeChargeId() == null || "".equals(user.getStripeChargeId())) {            MapcustomerParams = new HashMap();            customerParams.put("description", "Customer for test");            customerParams.put("source", stripePayRequestVO.getToken());            Customer c = null;            try {                c = Customer.create(customerParams);                user.setStripeChargeId(c.getId());                this.saveOrUpdate(user);                success("添加成功");            } catch (StripeException e) {                e.printStackTrace();            }        } else {            //  有這個用戶,就是修改他的唯一一張默認卡            try {                Customer c = Customer.retrieve(user.getStripeChargeId());                System.out.println("給客戶修改默認卡號");                MaptokenParam = new HashMap();                tokenParam.put("source", stripePayRequestVO.getToken());                c.update(tokenParam);                return success("修改成功");            } catch (StripeException e) {                System.out.println("異常了");                System.out.println(e);                e.printStackTrace();            }        }        return failure(ResponseEnum.EVENT_SYSTEM_ERROR_FAILURE);    }

              責任編輯:

              標簽:

              相關推薦:

              精彩放送:

              新聞聚焦
              Top 中文字幕在线观看亚洲日韩