Display BNPL Messaging公開プレビュー
Automatically explain buy now, pay later payment options.
To display promotional messaging for buy now, pay later payment options, use the Payment Method Messaging Element.
Set up StripeServer-sideClient-side
まず、Stripe アカウントが必要です。今すぐ登録してください。
Stripe iOS SDK はオープンソースです。詳細なドキュメントが提供されており、iOS 13 以降をサポートするアプリと互換性があります。
メモ
SDK の最新リリースおよび過去バージョンの詳細については、GitHub の Releases (リリース) ページをご覧ください。リポジトリのリリースをウォッチして、新しいリリースの公開時に通知を受け取ることも可能です。
アプリの起動時に Stripe 公開可能キーを使用して SDK を設定します。これにより、アプリが Stripe API にリクエストを送信できるようになります。
Initialize the Payment Method Messaging Element
Call create to instantiate the Payment Method Messaging Element with a PaymentMethodMessagingElement.. The Configuration object contains details about the potential purchase and how information about it should be displayed. After PaymentMethodMessagingElement has successfully initialized, put its view into your UI.
@_spi(PaymentMethodMessagingElementPreview) import StripePaymentSheet class MyViewController: UIViewController { private var amount = 1000 // $10.00 private var currency = "USD" private var paymentMethodMessagingElementView: UIView? func addPaymentMethodMessagingElement() { Task { @MainActor in // Create configuration object let configuration = PaymentMethodMessagingElement.Configuration( amount: amount, currency: currency, ) // Create PaymentMethodMessagingElement switch await PaymentMethodMessagingElement.create(configuration: configuration) { case .success(let element): let elementView = element.view self.view.addSubview(elementView) self.paymentMethodMessagingElementView = elementView // Set up constraints for elementView NSLayoutConstraint.activate([( // .. )]) case .noContent: // No element is available to display with this configuration // You may want to adapt your UI accordingly // ... case .failed(let error): // An unrecoverable error has occurred while attempting to load the element // You may want to log the error or take other action // ... } } } override func viewDidLoad() { super.viewDidLoad() // Set up the remainder of your page // ... addPaymentMethodMessagingElement() } }
オプションUpdate the element
If the customer performs an action that changes the configuration (for example, selecting a different product variant), initialize a new PaymentMethodMessagingElement instance to reflect the new information.
class MyViewController: UIViewController { // ... func updatePaymentMethodMessagingElement() { paymentMethodMessagingElementView?.removeFromSuperview() addPaymentMethodMessagingElement() } }
オプションCustomize the element
Customization options are available through the PaymentMethodMessagingElement. and PaymentMethodMessagingElement. objects.
// Configure appearance let appearance = PaymentMethodMessagingElement.Appearance( style: .flat, font: .boldSystemFont(ofSize: 12), textColor: .black, infoIconColor: .blue ) // Create configuration object let configuration = PaymentMethodMessagingElement.Configuration( amount: 1000, // $10.00 currency: "USD", locale: "en_GB", // Defaults to device locale but can be explicitly set countryCode: "US", // Defaults to customer IP address but can be explicitly set paymentMethodTypes: [.affirm, .klarna], // Defaults to dynamic payment methods from the Dashboard, but can be explicitly set appearance: appearance )