0

将 Paypal 与定制系统集成时,我设法将其设置为发送设定值,例如 25 英镑,但不是篮子中的变量,例如“GrandTotal”,这取决于客户在购物车中输入的内容(我有创建了我自己的购物车。)

请参考以下代码:

<%@ page language="C#"%>
<%@ Register TagPrefix="webxelcart" Namespace="WebXelCart" Assembly="WebXelCart" %>
<script runat="server">

void btnCheckout_Click(object sender, System.EventArgs e)
{
WriteToDB1.Save();
}

void WriteToDB1_RecordInserted(object sender, WebXelCart.RecordInsertedEventArgs e)
{
Cart1.OrderID = e.Identity;
SaveOrder1.Save();
}

    protected void Page_Load(object sender, EventArgs e)
    {

    }
</script>

<!doctype html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">


<script runat="server">  
    void Cart1_Load(object sender, System.EventArgs e)   
    { 
    if(Cart1.GrandTotal > 100){Cart1.CarriageCost = 0;} 
    else{Cart1.CarriageCost = 15;}  
    }  
    </script> 


<p align="center"><table width="100%" border="0" cellspacing="0" cellpadding="0" height="400">
  <tr>
    <td width="1" align="center" valign="top">&nbsp;<td width="100%" valign="top" 
          bgcolor="#f9f9f9" class="bodytxt">
<h1>Shopping Cart</h1>

        <webxelcart:cart ID="Cart1" ContainerControl="RptCartContents" ShopForMoreCmd="btnShopForMore" Tax="17.5" OnLoad="Cart1_Load" runat="server">
        <Fields><Field FieldName='Color' DataType='String'></Field></Fields>
        </webxelcart:cart>      

       <webxelcart:writetodb ID="WriteToDB1" ConnectionString="ConStr" ManualMode="true" DataBaseType="OleDb" DbTable="tblOrders" OnRecordInserted="WriteToDB1_RecordInserted" runat="server">
        <parameters>
          <parameter databasefield='CustomerID' value='<%# Cart1.CustomerID %>'></parameter>
          <parameter databasefield='GrandTotal' value='<%# Cart1.GrandTotal %>'></parameter>
          <parameter databasefield='SubTotal' value='<%# Cart1.SubTotal %>'></parameter>
          <parameter databasefield='TaxTotal' value='<%# Cart1.TaxTotal %>'></parameter>
        </parameters>
      </webxelcart:writetodb>

      <webxelcart:saveorder ID="SaveOrder1" DbTable="OrderLine" OrderIDField="OrderID" AfterSaveURL="payment.aspx" Cart="Cart1" ConnectionString="ConStr" ManualMode="true" DataBaseType="OleDb" runat="server">
 <fields>
 <field cartfield='Description' databasefield='Description'></field>
 <field cartfield='ID' databasefield='ProductID'></field>
 <field cartfield='Quantity' databasefield='Quantity'></field>
 <Field CartField='RawCost' DataBaseField='Cost'></Field>

 </fields></webxelcart:saveorder>

      <webxelcart:sendmail ID="SaveOrder2"   Cart="Cart1"  ManualMode="true" runat="server">
 <fields>
 <field cartfield='Description' databasefield='Description'></field>
 <field cartfield='ID' databasefield='ProductID'></field>
 <field cartfield='Quantity' databasefield='Quantity'></field>
 <Field CartField='RawCost' DataBaseField='Cost'></Field>

 </fields></webxelcart:sendmail>

      <br>
      <form method="post" id="form1" runat="server">
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><table width="100%" border="0" align="center" cellpadding="0" cellspacing="1">
              <tr>
                <td height="20" colspan="6" class="CartHeader">Customer Details</td>
              </tr>
              <tr>
                <td colspan="6" bgcolor="#f9f9f9" class="CartTotals"><table border="0" cellpadding="1" cellspacing="0">
                  <tr>
                    <td height="10" colspan="2"></td>
                    </tr>
                  <tr>
                    <td align="left"><h6>Name:&nbsp;</h6></td>
                    <td><%= Cart1["FirstName"] %> <%= Cart1["LastName"] %></td>
                  </tr>
                  <tr>
                    <td align="left" valign="top"><h6>Address:&nbsp;</h6></td>
                    <td><%= Cart1.PreserveLineBreaks(Cart1["Address"]) %></td>
                  </tr>
                  <tr>
                    <td align="left"><h6>Email :&nbsp;</h6></td>
                    <td><%= Cart1["EmailAddress"] %></td>
                  </tr>
                  <tr>
                    <td height="10" colspan="2"></td>
                  </tr>
                  <tr>
                    <td colspan="2"></td>
                    </tr>
                </table>           
                  </td>
                </tr>
              <tr>
                <td height="18" class="CartHeader"><h6>SKU</h6></td>
                <td class="CartHeader"><h6>Description</h6></td>
                <td align="center" class="CartHeader"><h6>Quantity</h6></td>
                <td align="right" class="CartHeader"><h6>Cost</h6></td>
                <td align="right" class="CartHeader"><h6>Total</h6></td>
              </tr>

              <asp:repeater ID="RptCartContents" DataMember="WebXeLShaperMainLoop" runat="server">
                <itemtemplate>
                  <tr>
                    <td height="18" class="CartRow"><%# DataBinder.Eval(Container.DataItem, "ID") %></td>
                    <td class="CartRow"><%# DataBinder.Eval(Container.DataItem, "Description") %></td>
                    <td align="center" class="CartRow"><%# DataBinder.Eval(Container.DataItem, "Quantity") %> </td>
                    <td align="right" class="CartRow"><%# Double.Parse(DataBinder.Eval(Container.DataItem, "Cost").ToString()).ToString("C") %>&nbsp;</td>
                    <td align="right" class="CartRow"><%# Double.Parse(DataBinder.Eval(Container.DataItem, "TotalCost").ToString()).ToString("C") %>
                    </td>
                  </tr>
                </itemtemplate>
                <footertemplate>
                  <tr>
                    <td height="18" colspan="4" align="right" class="CartTotals">Sub Total:</td>
                    <td align="right" class="CartTotals"><%# Double.Parse(Cart1.SubTotal.ToString()).ToString("C") %></td>
                  </tr>
                  <tr>
                    <td height="18" colspan="4" align="right" class="CartTotals">Carriage:</td>
                    <td align="right" class="CartTotals"><%# Double.Parse(Cart1.CarriageCost.ToString()).ToString("C") %></td>
                  </tr>
                  <tr>
                    <td height="18" colspan="4" align="right" class="CartTotals">Tax Total:</td>
                    <td align="right" class="CartTotals"><%# Double.Parse(Cart1.TaxTotal.ToString()).ToString("C") %></td>
                  </tr>
                  <tr>
                    <td height="18" colspan="4" align="right" class="CartTotals"><b>Grand Total:</b></td>
                    <td align="right" class="CartTotals"><b>
                      <%# Double.Parse(Cart1.GrandTotal.ToString()).ToString("C") %></b></td>
                  </tr>
                </footertemplate>
              </asp:repeater>

              <tr align="right">
              <td height="28" colspan="6" class="CartFooter">
<br /><br />
               <a class="button">Print Invoice <i class="icon-print"></i></a>

              </td>
              </tr>
              <tr align="center">
                <td height="28" colspan="6"></td>
              </tr>
            </table></td>
          </tr>
        </table>
    </form></td>
  </tr>
  <tr>
  </tr>
</table></p>

  </div>

  <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
  <input type="hidden" name="cmd" value="_cart">

  <input type="hidden" name="upload" value="1">
  <input type="hidden" name="business" value="seller_134342325468_biz@hotmail.co.uk">
  <input type="hidden" name="item_name_1" value="hg">
  <input type="hidden" name="amount" value="25.00"> 
  <input type="hidden" name="cbt" value="Return to The Store">
<input type="hidden" name="cancel_return" value="http://hg.site11.com">
  <input type="hidden" name="currency_code" value="GBP">


  <input type="hidden" name="image_url" id="edit-image-url" value="#"  />
  <input type="hidden" name="notify_url" value="#">
  <input type="hidden" name="return" value="http://www.hg.site11.com">
  <input type="submit" value="Proceed to Payment">
</form>

------------------------------------------------------------------------------------------------------------------------------------

.cs 文件:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class GoMerchant : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}

任何有关如何获取“GrandTotal”变量并将其发送到 Paypal 的帮助将不胜感激。

谢谢

4

1 回答 1

0

您不能form tag在 ASP.Net 页面中创建多个(除非 iframe),因为 ASP.Net 只允许在页面中使用一个表单标签。

你想在后面的代码中类似这样。它基本上收集用户输入的金额和数量,然后将其发送回 PayPal。

protected void btnCheckout_Click(object sender, EventArgs e) {

 string paypalUrl = IsTestMode ? 
   "https://www.sandbox.paypal.com/us/cgi-bin/webscr" : 
   "https://www.paypal.com/us/cgi-bin/webscr";

 var builder = new StringBuilder();

 builder.Append(paypalUrl);

 builder.AppendFormat("?cmd=_xclick&business={0}", 
    HttpUtility.UrlEncode(you@youremail.com));

 builder.Append("&lc=US&no_note=0&currency_code=GBP");

 builder.AppendFormat("&item_name={0}", 
    HttpUtility.UrlEncode(YourItemName));

 builder.AppendFormat("&amount={0}", AmountTextBox.Text);

 builder.AppendFormat("&return={0}", 
    HttpUtility.UrlEncode("http://mysite.cm/ReturnUrl"));

 builder.AppendFormat("&cancel_return={0}", 
    HttpUtility.UrlEncode("http://mysite.cm/CancelUrl"));

 builder.AppendFormat("&undefined_quantity={0}", QuantityTextBox.Text);

 HttpContext.Current.Response.Redirect(builder.ToString());

}
于 2013-04-03T14:50:17.333 回答