【问题标题】:how to pass Item description and Price to paypal page asp如何将项目描述和价格传递到贝宝页面 asp
【发布时间】:2014-09-10 14:21:03
【问题描述】:

当用户单击“立即购买”按钮时,我试图在重定向到贝宝页面时传递课程描述和价格。我不确定如何为此编码,而且我是 asp .net c# 的新手。请帮我。下面是html和c#代码。

   <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
         ConnectionString="<%$ ConnectionStrings:ASHAConnectionString %>"  
         SelectCommand="SELECT [TEMPLATE_NAME], [Price] FROM [TemplateMaster]">
   </asp:SqlDataSource>

     <asp:GridView ID="gvPayPalPrice" runat="server" DataSourceID="SqlDataSource1"
            AutoGenerateColumns="False" OnRowCommand="gvPayPalPrice_RowCommand"  
            BorderStyle="None" BorderWidth="1px" BackColor="#DEBA84" BorderColor="#DEBA84">

          <RowStyle ForeColor="#8C4510" BackColor="#FFF7E7" />
           <Columns>
               <asp:BoundField DataField="TEMPLATE_NAME" 
                     HeaderText="TEMPLATE_NAME" SortExpression="TEMPLATE_NAME" />
               <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
                    <asp:TemplateField HeaderText = "Buy Now">
                        <ItemTemplate>
                           <asp:ImageButton ID="imgbtnBuyNow" runat="server" ImageUrl="~/images/buy_now.png" Width="64" Height="64" CommandName="buy" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
                        </ItemTemplate>
                       </asp:TemplateField>
            </Columns>
            <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
            <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#FFF1D4" />
            <SortedAscendingHeaderStyle BackColor="#B95C30" />
            <SortedDescendingCellStyle BackColor="#F1E5CE" />
            <SortedDescendingHeaderStyle BackColor="#93451F" />
        </asp:GridView>

这是我用于传递到贝宝页面的 C# 代码。

protected void gvPayPalPrice_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "buy")
    {
        ImageButton ib = (ImageButton)e.CommandSource;
        int index = Convert.ToInt32(ib.CommandArgument);
        GridViewRow row =gvPayPalPrice.Rows[index];

        //Pay pal process Refer for what are the variable are need to send http://www.paypalobjects.com/IntegrationCenter/ic_std-variable-ref-buy-now.html

        string redirectUrl = "";

        //Mention URL to redirect content to paypal site
        redirectUrl += "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_xclick&business=" + ConfigurationManager.AppSettings["paypalemail"].ToString();

        //First name I assign static based on login details assign this value
        redirectUrl += "&first_name=Joe_Seller";

        //Product Name
       redirectUrl += "&item_name=" + CourseName.Text;

        //Product Amount
        redirectUrl += "&amount=" + CoursePrice.Text;

        //Business contact paypal EmailID
        redirectUrl += "&business=joekhaung@outlook.com";

        //Quantiy of product, Here statically added quantity 1
        redirectUrl += "&quantity=1";

        //If transactioin has been successfully performed, redirect SuccessURL page- this page will be designed by developer
        redirectUrl += "&return=" +      ConfigurationManager.AppSettings["SuccessURL"].ToString();


        //If transactioin has been failed, redirect FailedURL page- this page will be designed by developer
        redirectUrl += "&cancel_return=" + ConfigurationManager.AppSettings["FailedURL"].ToString();

        Response.Redirect(redirectUrl);
    }
}

【问题讨论】:

  • 那么问题是什么?

标签: c# asp.net paypal


【解决方案1】:

您在这里所做的只是构建一个付款标准网址。您需要做的就是将individual shopping cart item parameters 添加到您的字符串中,以便让这些显示如您所愿。

这是一个粗略的示例,说明您最终想要得到什么......

https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_xclick&business=some@email.com
&first_name=Tester&last_name=Testerson&amount=10.00
&return={your_return_url}&cancel={your_cancel_url}
&item_name_1=Test Widget #1&amount_1=5.00
&item_name_2=Test Widget #2&item_amount=5.00

为了便于阅读,我将其拆分为单独的行,但当然这只是一个长字符串/URL。

因此,您可能会循环访问某种类型的项目数组,并且您可以生成 URL 的该部分,然后将其附加到其余部分,就像您已经在此处所做的那样。

【讨论】:

    猜你喜欢
    • 2014-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-19
    • 2013-12-18
    • 1970-01-01
    • 2013-04-27
    相关资源
    最近更新 更多