public async Task <PaymentInfoResponse> DoTransaction(string baseUrl, PaymentInfoRequest paymentInfoRequest) { paymentInfoRequest.SystemTraceNr = RandomNumber(1000, 10000); paymentInfoRequest.ProcessingCode = RandomNumber(999, 9999).ToString(); PaymentInfoCommand paymentInfoCommand = new PaymentInfoCommand(); using (var httpClient = new HttpClient()) { using (var keyResponse = await httpClient.GetAsync(baseUrl + "/GetKey")) { string apiGetKeyResponse = await keyResponse.Content.ReadAsStringAsync(); string key = JObject.Parse(apiGetKeyResponse)["GetKeyResult"].ToString(); paymentInfoCommand.Key = key; paymentInfoCommand.EncyptedBody = _encryptionService.Encrypt(JsonConvert.SerializeObject(paymentInfoRequest), key); StringContent content = new StringContent(JsonConvert.SerializeObject(paymentInfoCommand), Encoding.UTF8, "application/json"); using (var response = await httpClient.PostAsync(baseUrl + "/Pay", content)) { string apiResponse = await response.Content.ReadAsStringAsync(); PaymentInfoResponse paymentInfoResponse = JsonConvert.DeserializeObject <PaymentInfoResponse>(apiResponse); return(paymentInfoResponse); } } } }
public override async Task <PaymentInfoResponse> PerformPayment(PaymentInfoRequest request, ServerCallContext context) { return(await Task.Run(() => { var num = new Random().Next(1000); return num > 500 ? new PaymentInfoResponse { Status = true } : new PaymentInfoResponse { Status = false }; })); }
public async Task <IActionResult> Index([Bind] PaymentInfoViewModel paymentInfo) { if (ModelState.IsValid) { PaymentInfoRequest paymentInfoRequest = new PaymentInfoRequest() { AmountTrxn = paymentInfo.AmountTrxn, CardHolder = paymentInfo.CardHolder, CurrencyCode = paymentInfo.CurrencyCode, CardNo = paymentInfo.CardNo, FunctionCode = paymentInfo.FunctionCode }; PaymentInfoResponse paymentInfoResponse = await _paymentService.DoTransaction(_configuration["PaymentServiceBaseUrl"].ToString(), paymentInfoRequest); return(RedirectToAction("SuccessPayment", new { code = paymentInfoResponse.ApprovalCode })); } else { //TODO add view error message return(View()); } }
protected void callDoPaymentPro(int pmi) { pmi = int.Parse(this.Request.QueryString["payment_method_id"]); string tm = DateTime.Now.ToString(); PaymentInfoRequest url = new PaymentInfoRequest(); url.api_username = SessionKey.apiuser; url.api_password = SessionKey.apipass; url.bank_payment_method_id = pmi.ToString(); url.bk_seller_email = SessionKey.Business; url.currency_code = "VND"; url.escrow_timeout = ""; url.extra_fields_value = ""; url.merchant_id = SessionKey.merchantid; url.order_description = ""; url.order_id = tm; url.payer_email = Session["email_payer"].ToString(); url.payer_message = ""; url.payer_name = "test"; url.payer_phone_no = Session["phone"].ToString(); url.payment_mode = "1"; url.shipping_address = ""; url.shipping_fee = ""; url.tax_fee = ""; url.total_amount = Session["price_bk"].ToString(); url.url_return = ""; //url.url_return = "http://localhost:52996/WebSite3/Baokim.aspx"; BKPaymentProService2 bk=new BKPaymentProService2(); PaymentInfoResponse baokim = new PaymentInfoResponse(); baokim=bk.DoPaymentPro(url); string link = baokim.url_redirect; if (baokim.error_code != "0") { throw new Exception(baokim.error_message); } else { Response.Redirect(baokim.url_redirect); } }
public async Task <ResponseMessage <PaymentInfoResponse> > Payment(UserInfo User, [FromBody] PaymentInfoRequest request) { var r = new ResponseMessage <PaymentInfoResponse>(); try { r = await _chargeManager.Payment(User, request); } catch (Exception e) { r.Code = ResponseCodeDefines.ServiceError; r.Message = "服务器错误:" + e.Message; Logger.Error("后补发票失败:\r\n{0}", e.ToString()); } return(r); }
public async Task <ResponseMessage <PaymentInfoResponse> > Payment(UserInfo user, PaymentInfoRequest request) { ResponseMessage <PaymentInfoResponse> r = new ResponseMessage <PaymentInfoResponse>(); var ci = await _Store.Get(request.ChargeId); if (ci == null) { r.Code = "404"; r.Message = "报销单不存在"; return(r); } bool hp = await _permissionExpansion.HavePermission(user.Id, PERMISSION_FYFK, ci.ReimburseDepartment); if (!hp) { r.Code = "403"; r.Message = "没有该报销单的操作权限"; return(r); } if (String.IsNullOrEmpty(request.Department)) { request.Department = user.OrganizationId; } if (String.IsNullOrWhiteSpace(request.BranchId)) { var org = await _orgUtils.GetNearParent(request.Department, orgTypes); if (org != null) { request.BranchId = org.Id; } else { request.BranchId = request.Department; } } if (String.IsNullOrWhiteSpace(request.PaymentNo)) { string prefix = await _orgUtils.GetBranchPrefix(request.BranchId, "XYH"); request.BranchPrefix = prefix; int seq = await _Store.GetPaymentNo(request.BranchId, prefix, DateTime.Now); request.Seq = seq; request.PaymentNo = String.Format("FK{0}{1}{2:D5}", prefix, DateTime.Now.ToString("yyyyMMdd"), seq); } var pi = _mapper.Map <PaymentInfo>(request); var r2 = await _Store.Payment(_mapper.Map <SimpleUser>(user), pi); r.Extension = _mapper.Map <PaymentInfoResponse>(r2); return(r); }