Exemple #1
0
        public async Task UpdateAsync(IMerchant merchant)
        {
            IMerchant existingMerchant = await _merchantRepository.GetAsync(merchant.Name);

            if (existingMerchant == null)
            {
                throw new MerchantNotFoundException(merchant.Name);
            }

            Mapper.Map(merchant, existingMerchant);

            await _merchantRepository.ReplaceAsync(existingMerchant);

            await _log.WriteInfoAsync(nameof(MerchantService), nameof(UpdateAsync),
                                      merchant.ToContext(),
                                      "Merchant updated");
        }
Exemple #2
0
        public async Task SetPublicKeyAsync(string merchantName, string publicKey)
        {
            IMerchant merchant = await _merchantRepository.GetAsync(merchantName);

            if (merchant == null)
            {
                throw new MerchantNotFoundException(merchantName);
            }

            merchant.PublicKey = publicKey;

            await _merchantRepository.ReplaceAsync(merchant);

            await _log.WriteInfoAsync(nameof(MerchantService), nameof(SetPublicKeyAsync),
                                      merchant.ToContext(),
                                      "Merchant public key updated");
        }
Exemple #3
0
        public async Task <IMerchant> CreateAsync(IMerchant merchant)
        {
            IReadOnlyList <IMerchant> merchants = await _merchantRepository.FindAsync(merchant.ApiKey);

            if (merchants.Count > 0)
            {
                throw new DuplicateMerchantApiKeyException(merchant.ApiKey);
            }

            IMerchant createdMerchant = await _merchantRepository.InsertAsync(merchant);

            await _log.WriteInfoAsync(nameof(MerchantService), nameof(CreateAsync),
                                      merchant.ToContext(),
                                      "Merchant created");

            return(createdMerchant);
        }