2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SquareのHello world

Posted at

はじめに

クレジットカード決済の仕組みを調べることがあって、気になったのでAPIの操作について少し勉強したのでメモとして残します。

内容

Squareというクレジットカード決済の仕組みのAPIについて記載します。API ExplorerというツールからAPIを操作して、サンドボックス環境でクレジットカード決済の画面を作って試してみます。またダッシュボードから結果を確認することができます。

Squareアカウントの作成とアプリケーションの作成

  • こちらからSquareのアカウントを作成します。
    image.png

  • 必要事項を入力して続行ボタンを押します。実質的に登録に必要となったのはメールアドレスのみでした。
    image.png

  • こちらからログインして「Create your first application」をクリックします。
    image.png

  • Application Nameを入力してSaveボタンをクリックします。
    image.png

  • できたアプリケーションをOpenします。
    image.png

  • CredentialsのページにあるApplication IDとAccess Tokenを使ってAPIを動かします。
    image.png

API ExplorerによるAPIの操作

  • API Explorer(https://developer.squareup.com/explorer/square)を開きます。
    image.png

  • プルダウンからLocation→Create Locationを選び、上で作ったAcces Tokenを入力します。
    image.png

  • 下記のような感じで入力してRun Requestボタンを押します。
    image.png

  • 成功すると下記のようなjsonレスポンスが返ってきます。
    image.png

  • 今度はプルダウンからCheckoutを選んで取得したlocation_idを入れます。
    image.png

  • Body部分でidempotency_keyをGenerateしたら、下記のような感じでorder情報を入力してRun Requestボタンを押します。
    image.png
    image.png

  • "checkout_page_url":"https://con***" というレスポンスが返ってくるので、そのURLを開くと、決済ページに行けます。
    image.png

  • Sandbox Test Valuesにあるカード番号を入れてPlace Orderボタンを押します。
    image.png

  • 決済が完了しました。
    image.png

Terminalからの実行

  • API ExplorerのcURLコマンドをCopyしてEC2のターミナルから実行してみると、下記のような結果が得られます。
    image.png

売り上げの管理

  • ダッシュボードから先ほどの売り上げの情報をチェックすることができます。
    image.png

おわりに

事業者がカード番号などの情報を持たずに決済ができる仕組みということがわかりました。ドキュメントがほとんど英語でとっつきにくいですが、サンドボックスやAPI Explorerなど試してみる環境は充実しているのではないかと思います。

参考文献

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?