Kom i gang. Det er Gratis
eller tilmeld med din email adresse
stripe af Mind Map: stripe

1. 其他

1.1. #charge 一次性付款 用payment 訂閱制付款 用subscription 會得到payment intent 這個建立後不知道什麼時候才會付款

1.1.1. stripe.checkout.Session.create( success_url="https://example.com/success", cancel_url="https://example.com/cancel", line_items=[ { "price": "price_1KE7CvD4jNr4OiEnCnSWyj8t", "quantity": 2, }, ], customer="cus_KiEnQLUfjpQ8IF", mode="payment", #subscription )

1.2. http://211-21-92-54.hinet-ip.hinet.net:8888/notebooks/stripe%EF%BC%BFapi.ipynb

2. # 支付需要的api, # 1. 取得帳號訂閱狀態 # 1-1. 是否訂閱 或買斷 # 1-2. 到期日 # 1-3. 付款資訊, 信用卡末四碼之類的(option) # 2. 取消訂閱 # 3. 購買或訂閱

3. 客戶資訊

3.1. 用email 去查 stripe.Customer.list

3.1.1. import stripe stripe.api_key = "sk_test_6JCo5EkHojgqN44usc4vDahZ00TZ0hAk4Y" stripe.Customer.list(limit=3,email="[email protected]")

3.2. 知道customer id 下: stripe.Customer.retrieve("cus_KiEnQLUfjpQ8IF")#[email protected]

3.2.1. 訂閱項目

3.2.1.1. print(jsonData['subscriptions']['data'][0]['items']) #訂閱資訊

3.2.1.2. print(jsonData['subscriptions']['data'][0]['items']['data'][0]['plan']['id']) #訂閱項目資訊

3.2.2. 基本付款資訊

3.2.2.1. print("信用卡末四碼"+jsonData['sources']['data'][0]['last4']) #信用卡資訊

3.2.2.2. print("信用卡到期日"+jsonData['sources']['data'][0]['exp_year']) #信用卡資訊

3.2.2.3. print("信用卡種類"jsonData['sources']['data'][0]['brand']) #信用卡資訊

3.3. 建立customer

3.3.1. 含付款資訊

3.3.1.1. 方法一#create a payment method

3.3.1.1.1. import stripe stripe.api_key = "sk_test_6JCo5EkHojgqN44usc4vDahZ00TZ0hAk4Y" stripe.PaymentMethod.create( type="card", card={ "number": "4242424242424242", "exp_month": 1, "exp_year": 2024, "cvc": "314", }, )

3.3.1.1.2. import stripe stripe.api_key = "sk_test_6JCo5EkHojgqN44usc4vDahZ00TZ0hAk4Y" paymentMethod="pm_1KECAuD4jNr4OiEnHzIgvyNj" stripe.Customer.create( payment_method=paymentMethod, email="[email protected]", invoice_settings={ 'default_payment_method': paymentMethod } )

3.3.1.2. 方法二#attach a payment method to a customer

3.3.1.2.1. #attach a payment method to a customer import stripe stripe.api_key = "sk_test_6JCo5EkHojgqN44usc4vDahZ00TZ0hAk4Y" stripe.PaymentMethod.attach( "pm_1KE7UhD4jNr4OiEnF0tc3m6E", #上一步驟的payment method customer="cus_KiEnQLUfjpQ8IF",#[email protected] )

3.3.2. 不含付款資訊

3.3.2.1. import stripe stripe.api_key = "sk_test_6JCo5EkHojgqN44usc4vDahZ00TZ0hAk4Y" stripe.Customer.create( email="[email protected]", )

4. 取消訂閱

4.1. #刪除訂閱,需要知道訂閱id

4.1.1. import stripe stripe.api_key = "sk_test_6JCo5EkHojgqN44usc4vDahZ00TZ0hAk4Y" stripe.Subscription.delete( "sub_1K7f4rD4jNr4OiEn2YRGeKoX", )

5. 付款

5.1. 先建立customer 再來使用訂閱或一次性

5.2. 一次性

5.2.1. #一次性付款,先看是否有此email過去資訊, 如果有就直接拿之前的。或是 新建立token 在把token給到charge

5.2.1.1. 有customer

5.2.1.1.1. import stripe stripe.api_key = "sk_test_6JCo5EkHojgqN44usc4vDahZ00TZ0hAk4Y" jsonData=stripe.Customer.list(limit=3,email="[email protected]") customerId="" customerId=jsonData['data'][0]['sources']['data'][0]['customer'] print("customer id:"+customerId)

5.2.1.1.2. charge = stripe.Charge.create( amount=999, currency='usd', description='Example charge', # source=token, customer=customerId, #目前ezyoutuber 沒有放customer )

5.2.1.2. 沒有customer

5.2.1.2.1. import stripe stripe.api_key = "sk_test_6JCo5EkHojgqN44usc4vDahZ00TZ0hAk4Y" tokenJson=stripe.Token.create( card={ "number": "4242424242424242", "exp_month": 1, "exp_year": 2023, "cvc": "314", }, ) tokenJson["id"]

5.2.1.2.2. 付款stripe.Charge.create

5.3. 訂閱制

5.3.1. subscription = stripe.Subscription.create( customer="cus_Ku0B67BljOEkJn", items=[ { "plan": "price_1H8NqVD4jNr4OiEngtktmLLF", }, ], ) subscription