vue集成stripe结算界面

37 篇文章 3 订阅
本文详细介绍了如何在Vue项目中集成Stripe支付,包括引入库、创建支付元素和处理支付流程。通过示例代码展示如何使用`@stripe/stripe-js`库创建支付表单,以及如何确认并处理支付结果。适用于需要实现在线支付功能的前端开发者。
摘要由CSDN通过智能技术生成

vue集成stripe结算界面

前言

本文章是集成stripe结账页面的文章
在这里插入图片描述
官方地址:

名称地址
收款https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements
自定义支付流程https://stripe.com/docs/payments/quickstart
元素外观APIhttps://stripe.com/docs/elements/appearance-api
支付场景https://stripe.com/docs/payments/more-payment-scenarios

一、引入库

文档:https://www.npmjs.com/package/@stripe/stripe-js

npm install @stripe/stripe-js

二、使用

html

 <form @submit.prevent="handleSubmit">
        <div id="payment-element"/>
        <el-button native-type="submit" type="primary" round >Complete</el-button>
</form>

js

<script>
import {toRaw} from '@vue/reactivity'
import {loadStripe} from "@stripe/stripe-js";
export default {
	data(){
		return{
		      stripe: undefined,
		      elements:undefined,
		}
	},
	method:{
	async initStripe() {
      this.stripe = await loadStripe('xxxxxxxxx');
      this.elements = this.stripe.elements({
        theme: 'stripe',
        clientSecret: 'xxxxxx',
        locale:'auto'
      })
      const paymentElement = this.elements.create("payment");
      paymentElement.mount("#payment-element");
    },
	},
	  async handleSubmit(e) {
      e.preventDefault();
      let elements=toRaw(this.elements)
      let stripe=toRaw(this.stripe)
      const {error} = await stripe.confirmPayment({
        elements,
        confirmParams: {
          // Make sure to change this to your payment completion page
          return_url: "http://localhost:4242/checkout.html",
        },
         //redirect: 'if_required'如果设置redirect: 'if_required'则不跳转returnUrl
      });
      console.log(error)
    },
      created() {
		this.initStripe()
  },
}
</script>

显示结果

在这里插入图片描述

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 13
    评论
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值