سلام.
قصد آموزش کد رو ندارم.فقط مراحلو میگم.
1.از آدرس سرور تست استفاده نکنید.چون دیگه این سرور وجود نداره.
2.https://pgws.bpm.bankmellat.ir/pgwchannel/services/pgw?wsdl
این آدرس رو تو رفرنسا اد کنید.
3.این کدها هم تو وب کانفیگتون بزارین:
<appSettings>
<add key="PgwSite" value="https://pgw.bpm.bankmellat.ir/pgwchannel/startpay.mellat"/>
<add key="TerminalId" value="Terminal ID"/>
<add key="UserName" value="UserName"/>
<add key="UserPassword" value="Password"/>
<add key="CallBackUrl" value="ReturnUrl"/>
<add key="BPService.Reference" value="https://pgws.bpm.bankmellat.ir/pgwchannel/services/pgw"/>
</appSettings>
4.این مقادیرو تعریف کنید:
public static readonly string PgwSite = ConfigurationManager.AppSettings["PgwSite"];
public static readonly string CallBackUrl = ConfigurationManager.AppSettings["CallBackUrl"];
public static readonly string TerminalId = ConfigurationManager.AppSettings["TerminalId"];
public static readonly string UserName = ConfigurationManager.AppSettings["UserName"];
public static readonly string UserPassword = ConfigurationManager.AppSettings["UserPassword"];
public static string RefId = "";
5.این کدها هم واسه دکمه پرداخت بنویسید:
try
{
string result;
BypassCertificateError();
BPService.PaymentGatewayClient bp = new BPService.PaymentGatewayClient();
result = bp.bpPayRequest(Int64.Parse(TerminalId),
UserName, UserPassword,Convert.ToInt64(orderID),
Int64.Parse(txtprice.Text),
SetDefaultDate(), SetDefaultTime(),
txtdiscription.Text, CallBackUrl, 0);
lblresult.Text = result;
String[] resultArray = result.Split(',');
if (resultArray[0] == "0")
ClientScript.RegisterStartupScript(typeof(Page), "ClientScript", "<script language='javascript' type='text/javascript'> postRefId('" + resultArray[1] + "');</script> ", false);
}
catch (Exception exp)
{
lblresult.Text = "Error: " + exp.Message;
}
6.این دو تا تابع هم برای گرفتن ساعت و تاریخ با فرمت درخواستی بانکه :
public string SetDefaultDate()
{
return DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString().PadLeft(2, '0') + DateTime.Now.Day.ToString().PadLeft(2, '0');
}
public string SetDefaultTime()
{
return DateTime.Now.Hour.ToString().PadLeft(2, '0') + DateTime.Now.Minute.ToString().PadLeft(2, '0') + DateTime.Now.Second.ToString().PadLeft(2, '0');
}
7.اینم اضافه کنید :
void BypassCertificateError()
{
ServicePointManager.ServerCertificateValidationCal lback +=
delegate(
Object sender1,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
return true;
};
}
8.این کد جاوا اسکریپتم تو همون صفحه پرداخت بزارین:
<script language="javascript" type="text/javascript">
function postRefId(refIdValue) {
var form = document.createElement("form");
form.setAttribute("method", "POST");
form.setAttribute("action", "<%= PgwSite %>");
form.setAttribute("target", "_self");
var hiddenField = document.createElement("input");
hiddenField.setAttribute("name", "RefId");
hiddenField.setAttribute("value", refIdValue);
form.appendChild(hiddenField);
document.body.appendChild(form);
form.submit();
document.body.removeChild(form);
}
</script>
9.خوب حالا میره سمت درگاه.اگه همه چی درست باشه.وقتی برگرده میره به همون آدرس برگشتی که دادین.
اونجا هم توابع bpVerifyRequest و bpSettleRequest را اجرا کنید و دیگه حله.
اگه جایی اشتباه بود ، بگید تا اصلاح کنم.
موفق باشید.
مابقی مراحل هم توضیح میدم...