public bool UpdateGCoinTransaction(IDbConnection db, gcoin_transaction gcoinTrans) { string stringSql = @"UPDATE gcoin_transaction SET amount=@amount, game_id=@game_id, description=@description, status=@status, ip_address=@ip_address, country_code=@country_code, payment_method=@payment_method, sender_email=@sender_email, receiver_email=@receiver_email, pay_key=@pay_key, pay_key_expiration_date=@pay_key_expiration_date, updated_at=@updated_at WHERE id = @id"; return 1 == db.Execute(stringSql, gcoinTrans); }
public int CreateGCoinTransaction(IDbConnection db, gcoin_transaction coinTrans) { string sql = @"INSERT INTO gcoin_transaction( customer_account_id, amount, game_id, description, order_id, status, ip_address, country_code, payment_method, sender_email, receiver_email, pay_key, pay_key_expiration_date, updated_at) VALUES ( @customer_account_id, @amount, @game_id, @description, @order_id, @status, @ip_address, @country_code, @payment_method, @sender_email, @receiver_email, @pay_key, @pay_key_expiration_date, @updated_at) RETURNING id"; return db.Query<int>(sql, coinTrans).FirstOrDefault(); }
public bool UpdateGCoinTransaction(gcoin_transaction gcoinTrans) { var repo = Repo.Instance; using (var db = repo.OpenConnectionFromPool()) { gcoinTrans.updated_at = DateTime.UtcNow; var result = repo.UpdateGCoinTransaction(db, gcoinTrans); if (result) StormFlushedGCoinTransaction(gcoinTrans.customer_account_id, gcoinTrans.id, gcoinTrans.status); return result; } }
public JsonResult convertGCoin(GCoinConvertViewModel model) { if (!ModelState.IsValid) { return Json(new { errors = Errors(ModelState) }); } if (!model.IsValidPassWord(CurrentUser.UserName)) return FailResult("password", Resources.Resources.Password_is_not_correct); if (!PaypalHelper.isReceiverEmailVerified(model.paypalEmail)) return FailResult("paypalEmail", Resources.Resources.Invalid_paypal_account); decimal gcoin = model.gcoin; string receiverEmail = model.paypalEmail; if (gcoin > CurrentUser.gcoin) return FailResult("gcoin", Resources.Resources.Invalid_GCoin_Convert); var api = GoPlayApi.Instance; gcoin_transaction transaction = new gcoin_transaction() { order_id = Guid.NewGuid().ToString(), customer_account_id = CurrentUser.Id, amount = -gcoin, //# Keeps it negative so sum(amount) works description = "Convert GCoin to USD, send to Paypal account: " + receiverEmail, status = Helper.GetDescription(TransactionStatus.Pending), payment_method = Helper.GetDescription(PaymentMethod.Convert_Gcoin), sender_email = ConfigurationManager.AppSettings["PAYPAL_SENDER_EMAIL"], receiver_email = receiverEmail }; transaction = api.CreateGCoinTransaction(transaction).Data; if (transaction == null) return FailResult("gcoin", ErrorCodes.ServerError.ToErrorMessage()); var autoMode = false; var pp = api.GetPaypalPreApproval(true).Data; if (pp != null) autoMode = true; var paymentResult = PaypalPayment(gcoin, receiverEmail, autoMode, transaction.order_id); string err = null; if (paymentResult.responseEnvelope.ack == AckCode.FAILURE) { transaction.status = Helper.GetDescription(TransactionStatus.Failure); err = "paypal: " + paymentResult.error[0].message; } else if (paymentResult.paymentExecStatus == "COMPLETED") { transaction.description = string.Format(GoPlayConstantValues.S_GCOIN_CONVERT_DESCRIPTION, Helper.displayDecimal(gcoin), receiverEmail); transaction.pay_key = paymentResult.payKey; transaction.status = Helper.GetDescription(TransactionStatus.Success); this.Flash(Resources.Resources.GCoin_transaction_is_successful, FlashLevel.Success); } else { transaction.pay_key = paymentResult.payKey; transaction.description = string.Format(GoPlayConstantValues.S_GCOIN_CONVERT_DESCRIPTION, Helper.displayDecimal(gcoin), receiverEmail); var paymentdetail = PaypalPaymentDetail(paymentResult.payKey); if (paymentdetail.responseEnvelope.ack == AckCode.SUCCESS) transaction.pay_key_expiration_date = DateTime.Parse(paymentdetail.payKeyExpirationDate); else transaction.pay_key_expiration_date = DateTime.UtcNow; transaction.status = Helper.GetDescription(TransactionStatus.Pending); this.Flash(Resources.Resources.GCoin_transaction_is_successful, FlashLevel.Success); } api.UpdateGCoinTransaction(transaction); if (err == null) return Json(new { success = true }); else return FailResult("gcoin", err); }
public Result<gcoin_transaction> CreateGCoinTransaction(gcoin_transaction gcoinTrans) { var repo = Repo.Instance; using (var db = repo.OpenConnectionFromPool()) { var newId = repo.CreateGCoinTransaction(db, gcoinTrans); if (newId > 0) StormFlushedCoinTransaction(newId, gcoinTrans.status); return repo.GetGcoinTransaction(db, newId); } }