Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix some service dependency #13

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ public IConfiguration GetConfiguration()

public async Task<MessageContract<IPaymentProvider>> GetPayment()
{
var serviceId = await GetReadableOf<ServiceEntity>().Select(x => x.Id).FirstOrDefaultAsync();
return await GetPayment(serviceId);
var service = await GetReadableOf<ServiceEntity>().FirstOrDefaultAsync();
return await GetPayment((service?.Id).GetValueOrDefault());
}

public async Task<MessageContract<IPaymentProvider>> GetPayment(long serviceId)
{
var service = await GetReadableOf<ServiceEntity>().Include(x => x.Addresses).FirstOrDefaultAsync(x => x.Id == serviceId);
service.Validate();
Console.WriteLine($"{serviceId} {service == null}");
var validate = service.Validate();
if (!validate)
return validate.ToContract<IPaymentProvider>();
var address = service.Addresses.First();
return new StripeProvider(address.ApiKey, new StripeClient(address.ApiKey, apiBase: address.Address));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using EasyMicroservices.PaymentsMicroservice.Database.Entities;
using EasyMicroservices.ServiceContracts;
using Microsoft.IdentityModel.Tokens;
using System.Linq;
using System.Text;

namespace EasyMicroservices.PaymentsMicroservice.Validations
Expand All @@ -11,7 +12,7 @@ public static MessageContract Validate(this ServiceEntity service)
{
if (service == null)
return (FailedReasonType.NotFound, "No service provider found in ServiceEntity, Please add your service provider!");
else if (service.Addresses.IsNullOrEmpty())
else if (service.Addresses.IsEmpty())
return (FailedReasonType.Empty, $"No address found for service provider Id: {service.Id}");
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ await queryable.AddAsync(new ServiceEntity()
new ServiceAddressEntity()
{
//ApiKey = "your live session",
//Address = StripeClient.DefaultApiBase
//Address = Stripe.StripeClient.DefaultApiBase
ApiKey = "testapikey",
Address = $"http://localhost:{PaymentComponentPort}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public async Task<MessageContract<CreateOrderResponseContract>> CreateOrderPorta
{
var orderContractLogic = _unitOfWork.GetLongContractLogic<OrderEntity, CreateOrderRequestContract, UpdateOrderRequestContract, OrderContract>();
var orderLogic = _unitOfWork.GetLogic<OrderEntity, long>();
request.ServiceId = 1;
var addedOrderId = await orderContractLogic.Add(request, cancellationToken).AsCheckedResult();
await OrderLogic.AddAndUpdateOrderStatus(addedOrderId, Payments.DataTypes.PaymentStatusType.Created , _unitOfWork);
var paymentOrderResponse = await OrderLogic.CreateOrder(request, _unitOfWork);
Expand Down
Loading