当用户点击“#34;立即购买”时,我正在尝试传递课程说明和价格时重定向到PayPal页面。按钮。我不知道如何编写代码,我是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>
这是我传递给paypal页面的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);
}
}
答案 0 :(得分:0)
您在这里所做的只是构建付款标准网址。您需要做的就是将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的那一部分,然后将它附加到其余部分,就像你已经在这里做的那样。