SlideShare uma empresa Scribd logo
1 de 20
最近やった
決済システムの実装の話
タケユー・ウェブ 竹内雄一 @takeyuweb
タケユー・ウェブ
竹内雄一
• さいたま市大宮周辺
• フリーランス8年目
• 基本ひとりで設計/実装/運用
• 高専クラスタ
• 昔rack-ketaiってgemを作った
ぐらい出典:ウィキメディア・コモンズ (Wikimedia Commons)
https://commons.wikimedia.org/w/index.php?title=File:JRW_mimasaka-emi_sta.jpg&oldid=149101608
限界集落で起業
ディーゼル気動車 on Rails (ワンマン運転)
事例
• 様々な支払い方法
• 様々な決済タイミング
• 様々な商材
• アフィリエイト対応
事例 様々な支払い方法
• 利用者が決済方法を選択できるようにして欲しい。
• 銀行振込
• クレジットカード
• 前回のクレジットカード(クイック決済)
• Edy
• 楽天ID決済
• PayPal Express Checkout
• 特定の条件でのみ選択できるもの。
• 楽天ID決済 … 楽天IDログインのみ
• 前回のクレジットカード(クイック決済)
• ※決済方法・業者はクライアント指定
事例 様々な決済タイミング
• 基本は毎回決済手続き
• 都度決済
• 会員プラン契約の支払いについては、次回以降は自動継続出来
るようにして欲しい。
• 自動定期決済
• また、初回はクレジットカード認証(オーソリ)だけで、無料
期間後自動課金したい。
• クレジットカード認証(オーソリ)
• 自動決済に失敗したら通知しつつ、都度決済に自動変更しつつ
猶予期限を設けたい。
事例 様々な商材
• プラン契約
• 課金後一定期間有効
• 上位プランへのアップグレードは差額支払い+延長
• 下位プランへのダウングレードは即時
• サービス内通貨(コイン)パック
• 購入後会員所有のパック規定のコインを加算
• 一定期間後失効
• 物品
• 購入者へ商品発送
• 上記はそれぞれ管理者が追加変更できるようにすること。
事例 アフィリエイト対応
• アフィリエイトリンクから獲得した会員の決済などのタイミン
グで成果を発生
• 自前のアフィリエイトシステム
• 外部のアフィリエイトASP
• チャージバック(決済取消)
• チャージバックが発生したら、自前のアフィリエイトシステムでの報
酬については取消
結構大変
• 様々な支払い方法
• 支払い方法ごとにフローが異なる
• 様々な決済タイミング
• 手動
• 商材ごとに別のUIから発生
• 自動
• 定期処理
• 様々な商材
• 商材ごとに決済後の処理が異なる
• アフィリエイト対応
• 支払い方法や商材の組み合わせで発生したりしなかったり
決済フレームワーク作っとくか
• 抽象化し、再利用可能なコードの共通化
• 簡単なルールで決済方法、商材の追加に対応
• 支払い方法は商材がどれかを知らなくて良いし、商材は決済方
法を知らなくても良い
• 呼び出し場所問わず、決済フローの開始・進行
• Controller
• Grape
• ActiveJob
• rake など
決済フレームワークを考える
(決済フロー)
• 共通の決済フロー括りだし
• 請求伝票発行
• 支払い完了
• ペンディング
• 差し戻し
• 支払い方法変更
• キャンセル
• 期限切れ失効 etc…
決済フレームワークを考える
(支払い方法)
• 共通インタフェースの括りだし
• 属性
• 名称
• 説明
• HTML(外部決済サービスへの接続など) etc…
• 利用可能チェック
• 決済フローの各イベント前後で必要な処理
• コールバック
• before_open(billing)
• after_open(billin)
• before_close(billing) etc…
• false を返したらロールバックして失敗を通知
決済フレームワークを考える
(商材)
• 共通インタフェースの括りだし
• 属性
• 商品名(見出し)
• 価格 など
• 購入可能チェック
• 決済フローの各イベント前後で必要な処理
• コールバック
• before_open(billing)
• after_open(billin)
• before_close(billing) etc…
• false を返したらロールバックして失敗を通知
決済フレームワークを実装する
• ドメインサービス的なもの? ※DDDよくわかってない
• 支払い方法オブジェクトと、商材インスタンスオブジェクトを
受け取って伝票を発行
• 行いたいフロー上のイベントを伝票を渡すとよしなに
• 利用者による操作
• 管理者による操作(銀行振込の入金を確認した、など)
• コンソールからの操作
• 決済代行会社のサーバからのコールバック etc…
billing = Payment.new(user).open(payment_method, product)
Payment.new(user).close(billing
)
支払い方法を実装する
• 「支払い方法」抽象クラスを作成
• 継承によって各支払い方法ごとに
必要なコールバックやビューを追
加
• 例)クレジットカード決済
• 決済代行会社へのリンク
• 決済代行会社からのコールバックのハ
ンドリング
• クレジットカード決済成功時に「前回
のクレジットカード」登録
• 銀行振込の入金があった場合の管理者
承認処理 etc…
• クライアント指定で実装はしな
かったけどStripeとかも組み込める
はず
商材を実装する
• 「商材」モジュールを作成する
• 各商材クラスにmix-inして必要な処理
を実装
• 例)契約の更新処理、差額を反映した
金額の計算、コインの加算処理 etc…
• ダックタイピング
• バリデーションしたいなら
item.class.include?(module)して
ArgumentError
• 継承を使わない
• STI(単一テーブル継承)
• 商材ごとに必要なカラムはいろいろ
• STIすると「あるモデルに不要なカラム」
がたくさん
アフィリエイトへの対応
• モジュールに分離
• アフィリエイトに対応させる支払い方法、商材にmix-inして必要に応じ
て実装
• 成果発生条件
• 成果率
• 決済取消時に成果を取り消す etc…
• 外部アフィリエイトASP
• 支払い結果にアフィエイト成果タグ埋め込み
定期自動決済の実装
• そこまでタイミングの要求が厳しくなかった(契約期限切れ後
猶予期間設定あり)
• CRON(whenever)
• 決済フレームワークを使って、「クイック決済」の伝票を発行、自動
決済ジョブを発行。
• 自動決済ジョブ(Active Job)
• 決済代行会社にリクエスト送信
• 応答やコールバックで決済フローを進める
• 失敗時一定回数リトライ
• だめなら、決済フレームワークの機能で支払い方法の変更を実行
定期自動決済とOpsWorks
• OpsWorks
• 負荷や時間に応じてインスタンスを増減
• CRONの問題
• 同じCRONタスクが複数のサーバで実行されてしまう
• CRON実行用のLayerを作成して、1つのインスタンスに設定
• CRON実行用Layer以外ではwheneverを使わないカスタムCookbook
• 決済代行会社への自動決済リクエスト送信元サーバIPの制限
• 自動決済ジョブを格納する専用キューを用意
• 自動決済用のLayerを作成して、1つのインスタンスに設定
• 自動決済用Layer以外では自動決済ジョブを実行しない
queue_as :payments
Ruby on Railsは
プログラミングではない?
• Ruby on Rails・・・に限らずフレームワークは道具
• 道具の使い方を覚えただけでマスターしたつもり?
• (僕含め)中級者にありがちな万能感
• どう使うかが大事=プログラミングだと思います。
以上

Mais conteúdo relacionado

Último

モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察  ~Text-to-MusicとText-To-ImageかつImage-to-Music...モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察  ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...博三 太田
 
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineerYuki Kikuchi
 
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NTT DATA Technology & Innovation
 
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdfAWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdfFumieNakayama
 
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)UEHARA, Tetsutaro
 
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?akihisamiyanaga1
 
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdfクラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdfFumieNakayama
 
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)Hiroshi Tomioka
 

Último (8)

モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察  ~Text-to-MusicとText-To-ImageかつImage-to-Music...モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察  ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...
 
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
 
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
 
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdfAWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
 
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
 
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
 
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdfクラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
 
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
 

Destaque

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destaque (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

最近やった決済システムの実装の話