用于POS信用卡刷卡的Windows窗体应用程序中的paypal沙盒测试帐户

时间:2015-04-30 09:53:41

标签: c# json rest paypal

  1. 我创建了一个Windows窗体应用程序示例。
  2. 我在visual studio下载pay pal sdk。
  3. 我创建了paypal沙盒测试帐户
  4. enter image description here 是谁添加凭证详细信息? enter image description here

    我们放了app id:

    沙箱测试AppID:

    APP-80W284485P519543T

    我点击了一个按钮即可复制winform app的一些代码。

     Dictionary<string, string> sdkConfig = new Dictionary<string, string>();
                sdkConfig.Add("mode", "sandbox");
                accessToken = new OAuthTokenCredential("AQkquBDf1zctJOWGKWUEtKXm6qVhueUEMvXO_-MCI4DQQ4-LWvkDLIN2fGsd", "EL1tVxAjhT7cJimnz5-Nsx9k2reTKSVfErNQF-CmrwJgxRtylkGTKlU4RvrX", sdkConfig).GetAccessToken();
    HttpContext CurrContext = HttpContext.Current;
                APIContext apiContext = new APIContext(accessToken);
                Item item = new Item();
                item.name = _ItemDescription;
                item.currency = "USD";
                item.price = _Amount;
                item.quantity = "1";
                item.sku = _UPC;
    
                List<Item> itms = new List<Item>();
                itms.Add(item);
                ItemList itemList = new ItemList();
                itemList.items = itms;
    
                Address billingAddress = new Address();
                billingAddress.city = "Chennai";
                billingAddress.country_code = "US";
                billingAddress.line1 = "11/12";
                billingAddress.line2 = "Andavar nager main street";
                billingAddress.postal_code = "600089";
                billingAddress.state = "Tamil nadu";
    
                CreditCard crdtCard = new CreditCard();
                crdtCard.billing_address = billingAddress;
                crdtCard.cvv2 = 2222;
                crdtCard.expire_month = 4;
                crdtCard.expire_year = 2020;
                crdtCard.first_name = "Arul";
                crdtCard.last_name = "Murugan";
                crdtCard.number = "4032039053301695";
                crdtCard.type = "visa";
    
                Details details = new Details();
                details.tax = "0";
                details.shipping = "0";
                details.subtotal = _Amount;
    
                Amount amont = new Amount();
                amont.currency = "USD";
                amont.total = _Amount;
                amont.details = details;
    
                Transaction tran = new Transaction();
                tran.amount = amont;
                tran.description = _ItemDescription;
                tran.item_list = itemList;
    
                List<Transaction> transactions = new List<Transaction>();
                transactions.Add(tran);
    
                FundingInstrument fundInstrument = new FundingInstrument();
                fundInstrument.credit_card = crdtCard;
    
                List<FundingInstrument> fundingInstrumentList = new List<FundingInstrument>();
                fundingInstrumentList.Add(fundInstrument);
    
                PayerInfo pi = new PayerInfo();
                pi.email = "sysumurugan-facilitator@gmail.com";
                pi.first_name = "Arul";
                pi.last_name = "Murugan";
    
    
                Payer payr = new Payer();
                payr.funding_instruments = fundingInstrumentList;
                payr.payment_method = "credit_card";
                payr.payer_info = pi;
    
                pi.shipping_address = new ShippingAddress
                {
                    city = "San Mateo",
                    country_code = "US",
                    line1 = "SO TEST",
                    line2 = "",
                    postal_code = "94002",
                    state = "CA",
                }; 
    
                Payment paymnt = new Payment();
                paymnt.intent = "sale";
                paymnt.payer = payr;
                paymnt.transactions = transactions;
                try
                {
                    Payment createdPayment = paymnt.Create(apiContext);
                    CurrContext.Items.Add("ResponseJson", JObject.Parse(createdPayment.ConvertToJson()).ToString(Formatting.Indented));
                }
                catch (PayPal.Exception.PayPalException ex)
                {
                    if (ex.InnerException is PayPal.Exception.ConnectionException)
                    {
                        CurrContext.Response.Write(((PayPal.Exception.ConnectionException)ex.InnerException).Response);
                    }
                    else
                    {
                        CurrContext.Response.Write(ex.Message);
                    }
                }
                catch (Exception es)
                {
                    MessageBox.Show( es.ToString());
                }
                CurrContext.Items.Add("RequestJson", JObject.Parse(paymnt.ConvertToJson()).ToString(Formatting.Indented));
    

    我的参考链接是

    http://pastebin.com/H7VuPQs4
    
    1. Parsing a PayPal REST Credit Card Transaction Response (JSON)
    2. C# PayPal REST API Checkout with Credit Card
    3. 请通过win form application向我展示POS(Point Of Sale)信用卡交易的任何其他方式。

1 个答案:

答案 0 :(得分:0)

PayPal .NET SDK适用于服务器应用程序(例如ASP.NET),其中应用程序凭据以安全的方式存储。直接从POS系统上运行的WinForms应用程序使用SDK会带来安全风险,因为您的商家帐户凭据不是以安全的方式存储的。理想情况下,POS系统应该在执行处理的某个地方与安全服务器进行通信。

话虽如此,这个用例是 PayPal Here 的目的。