陳力維  ·  3年前
2 貼文  ·  0 留言

[Stripe]前端第三方金流串接

==== Stripe IOS ====

=== 安裝方法 ===

CocoaPods

1.將此行添加到您的Podfile:

pod 'Stripe'

2.運行以下命令:

pod install

3.將來,要更新到最新版本的SDK,只需運行:

pod update Stripe

Swift

1.在專案appdelegate設定密鑰

import UIKit
import Stripe

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        Stripe.setDefaultPublishableKey("  public key  ")
        // do any other necessary launch configuration
        return true
    }
}

==== Stripe APPLE PAY ====

=== 安裝方法 ===

1.註冊獲取Apple商家ID

使用apple帳號建立merchant ID,建議格式 merchant.com.{{your_app_name}}

2.創建一個新的Apple Pay證書

1.從https://dashboard.stripe.com/settings/payments/apple_pay 獲取CSR 2.從第一步建立的商家ID,輸入CSR產出憑證 3.回到dashboard放入產出的憑證 遇到問題:格式不符無法輸入CSR 解決:輸入CSR格式選擇 not from china

3.與Xcode集成

功能添加apple pay,並加入商家ID,記得加入後打勾

==== Stripe 卡片測試 ====

4242424242424242    成功並立即處理付款。
4000002500003155    需要驗證。Stripe將觸發一個模式,要求客戶進行身份驗證。
4000000000009995    總是失敗,拒絕代碼為insufficient_funds。

==== Stripe APPLE PAY測試 ====

參考:https://developer.apple.com/cn/apple-pay/sandbox-testing/ 內有測試卡號

創建沙盒技術測試員帳戶
要創建沙盒技術測試員帳戶,請遵循以下步驟:

1.登錄 App Store Connect。
2.在主頁上,點按“用戶和訪問”。
3.在“沙盒技術”下方點按“測試員”。
4.點按添加按鈕“+”以建立測試員帳戶。
5.填寫測試員信息表單,並點按“邀請”。
6.在所有測試用設備上退出登錄您的 Apple ID,然後使用新的沙盒技術測試員帳戶重新登錄。

==== Stripe WEB ====

=== 安裝方法 ===

1.JS API在html加入

<script src="https://js.stripe.com/v3/"></script>

2.其他API用curl post data

=== 製作遇到的問題 ===

https://stripe.com/docs/stripe-js#html-js

只有createPaymentMethod必須使用js

createPaymentMethod必須使用stripe提供的UI,不會經手卡片資訊

var stripe = Stripe('public key');
var elements = stripe.elements();
var card = elements.create('card', {style: style});
card.mount('#card-element');
card.addEventListener('change', function(event) {
  var displayError = document.getElementById('card-errors');
  if (event.error) {
    console.log(event.error.message);
  } else {

  }
});

function createMethod(name,callback){
  var card=elements.getElement("card");
  stripe.createPaymentMethod({
    type:"card",
    card:card,
    billing_details:{
      name:name
    },
  })
  .then(function(result){
    console.log(result);
    //console.log(result.paymentMethod.id);
    callback(result);
  });
}

其餘API使用PHP CURL

<?php

//參考https://stripe.com/docs/api/customers?lang=curl

$ch = curl_init();
//echo '<pre>';print_r($this->config->stripe["secret_key"]);exit;

$key= "secret key";
$customer=$_POST["customer"];

// 設置 POST 數據
curl_setopt($ch, CURLOPT_URL,'https://api.stripe.com/v1/customers/'.$customer);
curl_setopt($ch, CURLOPT_USERPWD, $key);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// 執行句柄
$temp=curl_exec($ch);

curl_close($ch);

echo $temp;

?>

CURL curl_setopt參數對照

1.-d   POST
curl_setopt($ch, CURLOPT_POST, 1);

2.-d另帶參數
$temp=array(
  "customer" => $_POST["customer"]
);
$input=http_build_query($temp);
curl_setopt($ch, CURLOPT_POSTFIELDS, $input);

3.-u  輸入使用者身分
curl_setopt($ch, CURLOPT_USERPWD, $key);

4.-X+參數  指定方式傳送  如:-X POST
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");

5.-G  用get傳送
$url="https://api.stripe.com/v1/payment_methods";
$input=http_build_query($_POST);
curl_setopt($ch, CURLOPT_URL,$url."?".$input);

6.設定CURL不立刻回傳,回傳資料
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$temp=curl_exec($ch);
  分享   共 2,863 次點閱
按了喜歡:
共有 0 則留言
還沒有人留言。歡迎分享您的觀點、或是疑問。
您的留言
陳力維
2 貼文  ·  0 留言
查看所有文章