欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#實(shí)現(xiàn)Stripe支付的方法實(shí)踐

 更新時(shí)間:2022年02月14日 09:18:47   作者:新鑫S  
本文主要介紹了C#實(shí)現(xiàn)Stripe支付的方法實(shí)踐,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

Stripe支付首頁(yè)需要引用Stripe.net框架,我引用的是22.8.0版本,注意.NETFramework的版本為4.5,同時(shí)需要引用Newtonsoft.Json(版本不能低于9.0.1)和System.Collections.Immutable(版本不低于1.5.0)。

在這里插入圖片描述

一、前端JS代碼如下:

<script src="https://js.stripe.com/v3/"></script>
<script src="https://checkout.stripe.com/checkout.js"></script>
<script type="text/javascript">
	//Stripe支付
	var myStripe = {
		testKey: '<%=ConfigurationManager.AppSettings["pk_liveConfig"] %>', //配置文件中的key 這個(gè)從Stripe中取,我就不截圖展示了
		logoImg: "https://stripe.com/img/documentation/checkout/marketplace.png", //抬頭的Logo
		//換卡
		changeHandler: function (f) {
			return StripeButton.configure({
				key: this.testKey,
				image: f.logoImg || this.logoImg,
				name: f.title || 'Update Card Detail',
				panelLabel: f.button || 'Submit',
				allowRememberMe: false,
				locale: 'auto',
				dataKey: this.testKey,
				token: function (token) {
					f.email = token.email;
					f.tokenId = token.id;
					f.callback(f);
				}
			});
		},
		payHandler: function (f) {
			layer.closeAll(0);
			return StripeCheckout.configure({
				key: this.testKey,
				name: f.title || 'Stripe費(fèi)用',
				email: f.Email || '',
				currency: f.currency || 'zxx',
				amount: f.amount || 0,
				allowRememberMe: false,
				image: f.logoImg || this.logoImg,
				locale: 'auto',
				token: function (token) {
					f.tokenId = token.id;
					f.email = token.email;
					f.callback(f);
				}
			});
		},
		changeCard: function (f) {
			this.changeHandler(f).open();
		},
		pay: function (f) {
			this.payHandler(f).open();
		},
		SendMsg: function (uid) {
			var message = {};
			message.action = "noticeMember";
			message.code = 1;
			message.uid = uid;
			message.msg = "<div>已有用戶購(gòu)買(mǎi)了該照片!</div>";
			socketApi.sendMessage(message);
		}
	}
	myStripe.pay({
		title: 'TEST',
		currency: 'USD',//幣種:美元(USD)、人民幣(CNY)、港幣(HKD)
		amount: <%=Convert.ToInt32(acoumt) %> * 100,//金額
		callback: function (p) {
			$.ajax({
				type: 'POST',
				dataType: 'text',
				url: '/admin/ajax/PCBAOrdersData.ashx',
				data: 'param=Pay&email=' + this.email + "&amount=" + this.amount + "&tokenId=" + this.tokenId,
				success: function (data) {
					if (data == "succeeded") {
						location.href = "";//支付成功,跳轉(zhuǎn)頁(yè)面
					} else {
						layer.msg(data);
					}
				},
				error: function () {
				}
			})
		}
	});
</script>

效果如圖所示:

在這里插入圖片描述

二、后端C#代碼如下:

/// <summary>
/// Stripe支付
/// </summary>
public void Pay()
{
	string Msg = "Payment Failure";
	try
	{
		string tokenId = _Request.GetString("tokenId", "");
		string amount = _Request.GetString("amount", "0");
		string email = _Request.GetString("email", "");
		Stripe.StripeConfiguration.SetApiKey(ConfigurationManager.AppSettings["pk_liveSecretKey"]);

		var options = new Stripe.ChargeCreateOptions
		{
			Amount = Convert.ToInt64(amount),
			Currency = "USD",//幣種:美元(USD)、人民幣(CNY)、港幣(HKD)
			SourceId = tokenId,
			Description = "Stripe支付",//說(shuō)明
			ReceiptEmail = email,
		};
		var service = new Stripe.ChargeService();
		Stripe.Charge charge = service.Create(options);
		Msg = charge.Status;
	}
	catch (Exception e)
	{
		Msg = e.Message;
		throw e;
	}
	finally
	{
		HttpContext.Current.Response.Clear();
		HttpContext.Current.Response.Write(Msg);
		HttpContext.Current.Response.End();
	}
}

三、配置文件代碼如下:

<appSettings>
    <add key="pk_liveConfig" value="pk_test_XXXXXX"/><!--stripe賬號(hào)公鑰-->
    <add key="pk_liveSecretKey" value="sk_test_XXXXXX"/><!--stripe賬號(hào)Secret key-->
</appSettings>

Stripe支付的流程就是點(diǎn)擊支付按鈕就調(diào)用myStripe.pay函數(shù)去生成token,然后調(diào)用callback方法執(zhí)行后臺(tái)代碼,返回succeeded就是支付成功了

到此這篇關(guān)于C#實(shí)現(xiàn)Stripe支付的方法實(shí)踐的文章就介紹到這了,更多相關(guān)C# Stripe支付內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 基于WPF實(shí)現(xiàn)彈幕效果的示例代碼

    基于WPF實(shí)現(xiàn)彈幕效果的示例代碼

    這篇文章主要為大家詳細(xì)介紹了如何利用WPF實(shí)現(xiàn)彈幕效果,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)或工作有一定幫助,感興趣的小伙伴可以了解一下
    2022-09-09
  • Visual Studio C#創(chuàng)建windows服務(wù)程序

    Visual Studio C#創(chuàng)建windows服務(wù)程序

    用Visual C#創(chuàng)建Windows服務(wù)不是一件困難的事,本文就將指導(dǎo)你一步一步創(chuàng)建一個(gè)Windows服務(wù)并使用它,本文主要介紹了Visual Studio C#創(chuàng)建windows服務(wù)程序,感興趣的可以了解一下
    2024-01-01
  • Unity Shader實(shí)現(xiàn)序列幀動(dòng)畫(huà)效果

    Unity Shader實(shí)現(xiàn)序列幀動(dòng)畫(huà)效果

    這篇文章主要為大家詳細(xì)介紹了Unity Shader實(shí)現(xiàn)序列幀動(dòng)畫(huà)效果 ,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-02-02
  • C#實(shí)現(xiàn)FTP文件下載及超時(shí)控制詳解

    C#實(shí)現(xiàn)FTP文件下載及超時(shí)控制詳解

    這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)FTP文件下載及超時(shí)控制的相關(guān)知識(shí),文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-03-03
  • C#使用post發(fā)送和接收數(shù)據(jù)的方法

    C#使用post發(fā)送和接收數(shù)據(jù)的方法

    這篇文章主要介紹了C#使用post發(fā)送和接收數(shù)據(jù)的方法,涉及C#使用post收發(fā)數(shù)據(jù)的相關(guān)技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2015-04-04
  • Winform窗體圓角設(shè)計(jì)代碼

    Winform窗體圓角設(shè)計(jì)代碼

    這篇文章主要為大家詳細(xì)介紹了Winform窗體圓角設(shè)計(jì)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-01-01
  • C#操作ftp類(lèi)完整實(shí)例

    C#操作ftp類(lèi)完整實(shí)例

    這篇文章主要介紹了C#操作ftp類(lèi),以一個(gè)完整實(shí)例形式詳細(xì)分析了C#操作FTP文件傳輸所涉及的FTP連接、文件傳輸、參數(shù)設(shè)置、文件刪除等技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-09-09
  • c#系列 list詳情

    c#系列 list詳情

    這篇文章主要介紹了c#系列 list,list 本質(zhì)是一個(gè)數(shù)組,。就跟我們操作系統(tǒng)一樣,提前申請(qǐng)內(nèi)存大小。所以我們程序一般都有一個(gè)申請(qǐng)內(nèi)存,實(shí)際使用內(nèi)存,內(nèi)存碎片這幾個(gè)概念,下面?zhèn)z看文章詳細(xì)內(nèi)容吧
    2021-10-10
  • C#實(shí)現(xiàn)截圖工具小項(xiàng)目

    C#實(shí)現(xiàn)截圖工具小項(xiàng)目

    這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)截圖工具小項(xiàng)目,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-07-07
  • C#算法之各位相加

    C#算法之各位相加

    這篇文章介紹了C#算法之各位相加,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-01-01

最新評(píng)論