本文整理汇总了C#中Payment.Create方法的典型用法代码示例。如果您正苦于以下问题:C# Payment.Create方法的具体用法?C# Payment.Create怎么用?C# Payment.Create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Payment
的用法示例。
在下文中一共展示了Payment.Create方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Purchase
public string Purchase(string photoname, string size, string cost)
{
//Dictionary<string, string> sdkConfig = new Dictionary<string, string>();
//sdkConfig.Add("mode", "sandbox");
//string accessToken = new OAuthTokenCredential("Ae2ZWMxCl_ueuNy87vcg52hTjX9aVWfnvLQSMjDuTn2sj0crrWYIWwPseO_6H4nLpXKcHE9_DjtrmDEC", "EEmZr7iiuNCksXtPh5NjcVcguVGic0TwCW-f7GFmgfmrG8wBUhn_UJj53OxraTkKijC4UYQHv-fzlH7z", sdkConfig).GetAccessToken();
//APIContext apiContext = new APIContext(accessToken);
APIContext apiContext = GetAPIContext();
Amount amnt = new Amount();
amnt.currency = "USD";
amnt.total = cost;
List<Transaction> transactionList = new List<Transaction>();
Transaction tran = new Transaction();
tran.amount = amnt;
tran.description = "Photo";
tran.description = "creating a payment";
tran.item_list = new ItemList();
tran.item_list.items = new List<Item>();
tran.item_list.items.Add(new Item());
Item item = new Item();
tran.item_list.items[0].currency = "USD";
tran.item_list.items[0].description = size;
tran.item_list.items[0].name = photoname;
string price = cost;
tran.item_list.items[0].price = price;// "12";
tran.item_list.items[0].quantity = 1.ToString();// "1";
tran.item_list.items[0].sku = photoname + " " + size;
tran.item_list.items[0].tax = "0";
transactionList.Add(tran);
Payer payr = new Payer();
payr.payment_method = "paypal";
payr.payer_info = new PayerInfo();
RedirectUrls redirUrls = new RedirectUrls();
redirUrls.cancel_url = Request.Url + "";
string tempurl = "http://" + Request.Url.Authority + "/Home/Confirm";
redirUrls.return_url = tempurl;
Payment pymnt = new Payment();
pymnt.intent = "sale";
pymnt.payer = payr;
pymnt.transactions = transactionList;
pymnt.redirect_urls = redirUrls;
Payment createdPayment = pymnt.Create(apiContext);
Links approvalURL = new Links();
for (int i = 0; i < createdPayment.links.Count; ++i)
{
if (createdPayment.links[i].rel == "approval_url")
{
approvalURL = createdPayment.links[i];
i = createdPayment.links.Count;
}
}
return approvalURL.href;
}