Translation disclaimer

Documentation is written in English and subsequently translated. This page, therefore, might not have the most up-to-date content. If any questions arise relating to the accuracy of the translated content, please refer to the English version of the page.

Menu

カードで支払うセッションの作成

Web SDKでsessionを作成することにより、顧客のカード詳細を保護します。

完全統合のサンプルコード

Copied!
<section class="container">
    <section class="card">
        <form class="checkout" id="card-form">

            <label class="label" for="card-pan">Card number <span class="type"></span></label>
            <section id="card-pan" class="field"></section>

            <section class="col-2">
                <section class="col">
                    <label class="label" for="card-expiry">Expiry date</label>
                    <section id="card-expiry" class="field"></section>
                </section>

                <section class="col">
                    <label class="label" for="card-cvv">CVV</label>
                    <section id="card-cvv" class="field"></section>
                </section>
            </section>

            <button class="submit" type="submit">Pay Now</button>
        </form>
        <button class="clear" id="clear">Clear</button>
    </section>
</section>

<script src="https://try.access.worldpay.com/access-checkout/v2/checkout.js"></script>

// For production change to "https://access.worldpay.com/access-checkout/v2/checkout.js"
body {
  font: 11px/22px sans-serif;
  text-transform: uppercase;
  background-color: #f7f7f7;
  color: black;
}

.container {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.card {
  position: relative;
  background: white;
  padding: 40px 30px;
  top: -30px;
  width: 100%;
  max-width: 300px;
  border-radius: 12px;
  box-shadow: 3px 3px 60px 0px rgba(0, 0, 0, 0.1);
}
.card .checkout .col-2 {
  display: flex;
}
.card .checkout .col-2 .col:first-child {
  margin-right: 15px;
}
.card .checkout .col-2 .col:last-child {
  margin-left: 15px;
}
.card .checkout .label .type {
  color: green;
}
.card .checkout.visa .label .type:before {
  content: "(visa)";
}
.card .checkout.mastercard .label .type:before {
  content: "(master card)";
}
.card .checkout.amex .label .type:before {
  content: "(american express)";
}
.card .checkout .field {
  height: 40px;
  border-bottom: 1px solid lightgray;
}
.card .checkout .field#card-pan {
  margin-bottom: 30px;
}
.card .checkout .field.is-onfocus {
  border-color: black;
}
.card .checkout .field.is-empty {
  border-color: orange;
}
.card .checkout .field.is-invalid {
  border-color: red;
}
.card .checkout .field.is-valid {
  border-color: green;
}
.card .checkout .submit {
  background: red;
  position: absolute;
  cursor: pointer;
  left: 50%;
  bottom: -60px;
  width: 200px;
  margin-left: -100px;
  color: white;
  outline: 0;
  font-size: 14px;
  border: 0;
  border-radius: 30px;
  text-transform: uppercase;
  font-weight: bold;
  padding: 15px 0;
  transition: background 0.3s ease;
}
.card .checkout.is-valid .submit {
  background: green;
}

.clear {
  background: grey;
  position: absolute;
  cursor: pointer;
  left: 50%;
  bottom: -120px;
  width: 200px;
  margin-left: -100px;
  color: white;
  outline: 0;
  font-size: 14px;
  border: 0;
  border-radius: 30px;
  text-transform: uppercase;
  font-weight: bold;
  padding: 15px 0;
  transition: background 0.3s ease;
}
(function () {
    var form = document.getElementById("card-form");
    var clear = document.getElementById("clear");
    Worldpay.checkout.init(
      {
        id: "your-checkout-id",
        form: "#card-form",
        fields: {
          pan: {
            selector: "#card-pan",
            placeholder: "4444333322221111"
          },
          cvv: {
            selector: "#card-cvv",
            placeholder: "123"
          },
          expiry: {
            selector: "#card-expiry",
            placeholder: "MM/YY"
          }
        },
        styles: {
          "input": {
            "color": "black",
            "font-weight": "bold",
            "font-size": "20px",
            "letter-spacing": "3px"
          },
          "input#pan": {
            "font-size": "24px"
          },
          "input.is-valid": {
            "color": "green"
          },
          "input.is-invalid": {
            "color": "red"
          },
          "input.is-onfocus": {
            "color": "black"
          }
        },
        accessibility: {
          ariaLabel: {
            pan: "my custom aria label for pan input",
            expiry: "my custom aria label for expiry input",
            cvv: "my custom aria label for cvv input"
          },
          lang: {
            locale: "en-GB"
          },
          title: {
            enabled: true,
            pan: "my custom title for pan",
            expiry: "my custom title for expiry date",
            cvv: "my custom title for security code"
          }
        },
        acceptedCardBrands: ["amex", "diners", "discover", "jcb", "maestro", "mastercard", "visa"]
      },
      function (error, checkout) {
        if (error) {
          console.error(error);
          return;
        }

        form.addEventListener("submit", function (event) {
          event.preventDefault();

          checkout.generateSessionState(function (error, sessionState) {
            if (error) {
              console.error(error);
              return;
            }
            
            // session state for card details
            alert(sessionState);
          });
        });

        clear.addEventListener("click", function(event) {
          event.preventDefault();
          checkout.clearForm(function() {
            // trigger desired behaviour on cleared form
            console.log('Form successfully cleared');
          });
        });
      }
    );
  })();

チェックアウトフォームの作成

フォームを作成するときは、一意の識別子とフィールド構成を使用しなければなりません。次に、デフォルトの高さをフィールドに適用しなければなりません。

フィールド構成に一意の識別子を設定する方法例:

HTML

Copied!
<form class="checkout" id="card-form">
      <label class="label" for="card-pan">Card number <span class="type"></span></label>
      <section id="card-pan" class="field"></section>
      <section class="col-2">
        <section class="col">
          <label class="label" for="card-expiry">Expiry date</label>
        <section id="card-expiry" class="field"></section>
        </section>
        <section class="col">
          <label class="label" for="card-cvv">CVV</label>
          <section id="card-cvv" class="field"></section>
        </section>
      </section>
      <button class="submit" type="submit">Pay Now</button>
    </form>

また、チェックアウトページのレイアウトを設定する方法例:

CSS

Copied!
.card .checkout .col-2 {
  display: flex;
}
.card .checkout .col-2 .col:first-child {
  margin-right: 15px;
}
.card .checkout .col-2 .col:last-child {
  margin-left: 15px;
}
.card .checkout .field {
  height: 40px;
  border-bottom: 1px solid lightgray;
}
.card .checkout .field#card-pan {
  margin-bottom: 30px;
}

SDKの初期化

SDKを取得し、フォームとフィールドの構成を設定するためのスクリプトを含めたら、SDKを初期化しなければなりません。

これを行うには、Worldpay.checkout.init方法を使用します。

SDKを初期化するときは、AccessCheckoutIdentity、一意のフォームIDとフィールド構成を提供しなければなりません。

オプションの構成

次のものを提供することもできます。

例 - SDKを初期化します(必須パラメーター/構成)

JavaScript

Copied!
(function () {
    var form = document.getElementById("card-form");
    var clear = document.getElementById("clear");
    Worldpay.checkout.init(
      {
        id: "your-checkout-id",
        form: "#card-form",
        fields: {
          pan: {
            selector: "#card-pan",
            placeholder: "4444333322221111"
          },
          cvv: {
            selector: "#card-cvv",
            placeholder: "123"
          },
          expiry: {
            selector: "#card-expiry",
            placeholder: "MM/YY"
          }
        },
        styles: {
          "input": {
            "color": "black",
            "font-weight": "bold",
            "font-size": "20px",
            "letter-spacing": "3px"
          },
          "input#pan": {
            "font-size": "24px"
          },
          "input.is-valid": {
            "color": "green"
          },
          "input.is-invalid": {
            "color": "red"
          },
          "input.is-onfocus": {
            "color": "black"
          }
        },
        accessibility: {
          ariaLabel: {
            pan: "my custom aria label for pan input",
            expiry: "my custom aria label for expiry input",
            cvv: "my custom aria label for cvv input"
          },
          lang: {
            locale: "en-GB"
          },
          title: {
            enabled: true,
            pan: "my custom title for pan",
            expiry: "my custom title for expiry date",
            cvv: "my custom title for security code"
          }
        },
        acceptedCardBrands: ["amex", "diners", "discover", "jcb", "maestro", "mastercard", "visa"]
      },
      function (error, checkout) {
        if (error) {
          console.error(error);
          return;
        }

        form.addEventListener("submit", function (event) {
          event.preventDefault();

          checkout.generateSessionState(function (error, sessionState) {
            if (error) {
              console.error(error);
              return;
            }
            
            // session state for card details
            alert(sessionState);
          });
        });

        clear.addEventListener("click", function(event) {
          event.preventDefault();
          checkout.clearForm(function() {
            // trigger desired behaviour on cleared form
            console.log('Form successfully cleared');
          });
        });
      }
    );
  })();
必須パラメーターの説明
idアクセスチェックアウトID。 e.g. f7a25ad0-0224-46c2-9102-2229aaadbfec
form独自のフォーム#idセレクター。
stylesオプションのスタイルオブジェクト構成。
fieldsフィールド構成を含むオブジェクト。
selector特定のフィールドの#idセレクター。
placeholder顧客がフィールドに入力する必要のある情報のタイプを示すオプションのテキストプレビュー。
accessibilityオプションのアクセシビリティオブジェクト構成。
cardBrands受け入れたいカードブランドのオプションの配列。
enablePanFormatting呼び出された場合にPAN形式動作を有効にするオプションのパラメーター。

上記のJava Scriptの例では、sessionStateが返され、顧客のカード詳細の暗号化されたペイロードが含まれています。

詳細:sessionStateの詳細については、こちらをクリックしてください。

Verified Tokens API(検証済みトークンAPI)へのリクエストのsession支払の受理に使用できるトークンを受け取ります。

重要:sessionの寿命は1分間で、一度しか使用できません。その時間内にトークンを作成しない場合は、新しいsessionを作成しなければなりません。

フォームの消去

SDKは、SDKをリセットできるようにするclearForm方法も公開しています。SDKをリロードせずに、すべてのフィールドとクラスが元の状態に戻されます。

clearForm方法は、フォーム全体が正常に消去されたときに呼び出されるコールバックを受け入れます。

通常、顧客の行動がこれをトリガーします。例:

  • 消去フォームボタンをクリックする
  • sessionの正常な受理

顧客はSDKをリロードせずにカードの詳細の複数のセットを入力できます。

SDKの削除

remove方法を使用してページからSDKを削除できます。この方法は、SDKによってページに追加されたすべてのフィールドを削除します。

ブラウザのサポート

  • マイナーバージョン1.7.0はFirefox、Edge Legacy、Chrome> = 91をサポートしていません
  • マイナーバージョン1.7.1はEdge LegacyとChrome> = 91をサポートしていません
  • マイナーバージョン1.7.2はChrome> = 91をサポートしていません(問題は1.7.3で修正されました)

他のすべてのバージョンでは、主要なブラウザのすべての最新バージョンをサポートしています。


次の手順


[確認済みトークン]の作成(/ja/docs/access-worldpay/verified-tokens/create-verified-token)