#Stripe API로 정기 결제 = 구독 평가판 기간 테스트하기 ( #Ruby )

9006 단어 스트라이프루비

NOTE


  • 공식적으로, 곧 끝나는 평가판 기간을 설정하여 테스트하는 것이 좋습니다.
  • trial_end를 몇 초 후에 설정하여 구독을 만듭니다.
  • 0 엔의 청구가 즉시 발생하여 청구 성공 취급이되는 것 같다.
  • 곧 가입의 과금주기가 시작되지만 그 전에 일단 스케줄 등록 상태가 될 것 같습니다
  • trial_end와 billing_cycle_anchor는 정확히 같은 시간이 될 것 같습니다.

    코드


    require 'stripe'
    
    Stripe.api_key = 'sk_test_xxxxxxxxxxx'
    
    product = Stripe::Product.create(name: 'Gold plan')
    plan = Stripe::Plan.create(interval: 'month', currency: 'jpy', amount: 1000, product: product.id)
    tax_rate = Stripe::TaxRate.create(display_name: 'Tax Rate', percentage: 10.0, inclusive: false)
    customer = Stripe::Customer.create
    payment_method = Stripe::PaymentMethod.create(type: 'card', card: { number: '4242424242424242', exp_year: 2030, exp_month: 01})
    customer_payment_method = Stripe::PaymentMethod.attach(payment_method.id, customer: customer.id)
    
    subscription = Stripe::Subscription::create( customer: customer.id, default_payment_method: customer_payment_method.id, items: [{ plan: plan.id }], default_tax_rates: [tax_rate], trial_end: (Time.now.to_i + 5) )
    
    

    Result e.g


    => #<Stripe::Subscription:0x3fcd2c9f3128 id=sub_GQKh4eG0ZMm7JQ> JSON: {
      "id": "sub_GQKh4eG0ZMm7JQ",
      "object": "subscription",
      "application_fee_percent": null,
      "billing_cycle_anchor": 1577257942,
      "billing_thresholds": null,
      "cancel_at": null,
      "cancel_at_period_end": false,
      "canceled_at": null,
      "collection_method": "charge_automatically",
      "created": 1577257937,
      "current_period_end": 1577257942,
      "current_period_start": 1577257937,
      "customer": "cus_GQKbTifs2Duhwe",
      "days_until_due": null,
      "default_payment_method": "pm_1FtTwUCmti5jpytUxyBlAksI",
      "default_source": null,
      "default_tax_rates": [
        {"id":"txr_1FtTwTCmti5jpytUnwwi2w3L","object":"tax_rate","active":true,"created":1577257561,"description":null,"display_name":"Tax Rate","inclusive":false,"jurisdiction":null,"livemode":false,"metadata":{},"percentage":10.0}
      ],
      "discount": null,
      "ended_at": null,
      "invoice_customer_balance_settings": {"consume_applied_balance_on_void":true},
      "items": {"object":"list","data":[{"id":"si_GQKhUmcJsQVkTh","object":"subscription_item","billing_thresholds":null,"created":1577257937,"metadata":{},"plan":{"id":"plan_GQKbfgYG7NGBrH","object":"plan","active":true,"aggregate_usage":null,"amount":1000,"amount_decimal":"1000","billing_scheme":"per_unit","created":1577257561,"currency":"jpy","interval":"month","interval_count":1,"livemode":false,"metadata":{},"nickname":null,"product":"prod_GQKbZMaRTjX4Wa","tiers":null,"tiers_mode":null,"transform_usage":null,"trial_period_days":null,"usage_type":"licensed"},"quantity":1,"subscription":"sub_GQKh4eG0ZMm7JQ","tax_rates":[]}],"has_more":false,"total_count":1,"url":"/v1/subscription_items?subscription=sub_GQKh4eG0ZMm7JQ"},
      "latest_invoice": "in_1FtU2XCmti5jpytUzWEhiZLq",
      "livemode": false,
      "metadata": {},
      "next_pending_invoice_item_invoice": null,
      "pending_invoice_item_interval": null,
      "pending_setup_intent": null,
      "plan": {"id":"plan_GQKbfgYG7NGBrH","object":"plan","active":true,"aggregate_usage":null,"amount":1000,"amount_decimal":"1000","billing_scheme":"per_unit","created":1577257561,"currency":"jpy","interval":"month","interval_count":1,"livemode":false,"metadata":{},"nickname":null,"product":"prod_GQKbZMaRTjX4Wa","tiers":null,"tiers_mode":null,"transform_usage":null,"trial_period_days":null,"usage_type":"licensed"},
      "quantity": 1,
      "schedule": null,
      "start_date": 1577257937,
      "status": "trialing",
      "tax_percent": 10.0,
      "trial_end": 1577257942,
      "trial_start": 1577257937
    }
    

    대시보드







    Ref



    Using trial periods on subscriptions | Stripe Billing
    htps : // st 리페. 코 m / 두 cs / 병 g / su bsc p chion s / thia ls

    Original by Github issue

  • 좋은 웹페이지 즐겨찾기