コード例 #1
0
        //private void GetAddress(OrderReferenceDetailsResponse details, Address address, out bool countryAllowsShipping, out bool countryAllowsBilling)
        //{
        //	countryAllowsShipping = countryAllowsBilling = true;

        //	address.Email = details.GetEmail();
        //	address.ToFirstAndLastName(details.GetBuyerName());
        //	address.Address1 = details.GetAddressLine1().EmptyNull().Trim().Truncate(4000);
        //	address.Address2 = details.GetAddressLine2().EmptyNull().Trim().Truncate(4000);
        //	address.Address2 = address.Address2.Grow(details.GetAddressLine3().EmptyNull().Trim(), ", ").Truncate(4000);
        //	address.City = details.GetCity().EmptyNull().Trim().Truncate(4000);
        //	address.ZipPostalCode = details.GetPostalCode().EmptyNull().Trim().Truncate(4000);
        //	address.PhoneNumber = details.GetPhone().EmptyNull().Trim().Truncate(4000);

        //	var countryCode = details.GetCountryCode();
        //	if (countryCode.HasValue())
        //	{
        //		var country = _countryService.GetCountryByTwoOrThreeLetterIsoCode(countryCode);
        //		if (country != null)
        //		{
        //			address.CountryId = country.Id;
        //			countryAllowsShipping = country.AllowsShipping;
        //			countryAllowsBilling = country.AllowsBilling;
        //		}
        //	}

        //	var stateRegion = details.GetStateOrRegion();
        //	if (stateRegion.HasValue())
        //	{
        //		var stateProvince = _stateProvinceService.GetStateProvinceByAbbreviation(stateRegion);
        //		if (stateProvince != null)
        //		{
        //			address.StateProvinceId = stateProvince.Id;
        //		}
        //	}

        //	// Normalize.
        //	if (address.Address1.IsEmpty() && address.Address2.HasValue())
        //	{
        //		address.Address1 = address.Address2;
        //		address.Address2 = null;
        //	}
        //	else if (address.Address1.HasValue() && address.Address1 == address.Address2)
        //	{
        //		address.Address2 = null;
        //	}

        //	if (address.CountryId == 0)
        //	{
        //		address.CountryId = null;
        //	}

        //	if (address.StateProvinceId == 0)
        //	{
        //		address.StateProvinceId = null;
        //	}
        //}

        //private bool FindAndApplyAddress(OrderReferenceDetailsResponse details, Customer customer, bool isShippable, bool forceToTakeAmazonAddress)
        //{
        //	// PlaceOrder requires billing address but we don't get one from Amazon here. so use shipping address instead until we get it from amazon.
        //	var countryAllowsShipping = true;
        //	var countryAllowsBilling = true;

        //	var address = new Address();
        //	address.CreatedOnUtc = DateTime.UtcNow;

        //	GetAddress(details, address, out countryAllowsShipping, out countryAllowsBilling);

        //	if (isShippable && !countryAllowsShipping)
        //		return false;

        //	if (address.Email.IsEmpty())
        //	{
        //		address.Email = customer.Email;
        //	}

        //	if (forceToTakeAmazonAddress)
        //	{
        //		// First time to get in touch with an amazon address.
        //		var existingAddress = customer.Addresses.ToList().FindAddress(address, true);
        //		if (existingAddress == null)
        //		{
        //			customer.Addresses.Add(address);
        //			customer.BillingAddress = address;
        //		}
        //		else
        //		{
        //			customer.BillingAddress = existingAddress;
        //		}
        //	}
        //	else
        //	{
        //		if (customer.BillingAddress == null)
        //		{
        //			customer.Addresses.Add(address);
        //			customer.BillingAddress = address;
        //		}

        //		GetAddress(details, customer.BillingAddress, out countryAllowsShipping, out countryAllowsBilling);

        //		// But now we could have dublicates.
        //		var newAddressId = customer.BillingAddress.Id;
        //		var addresses = customer.Addresses.Where(x => x.Id != newAddressId).ToList();

        //		var existingAddress = addresses.FindAddress(customer.BillingAddress, false);
        //		if (existingAddress != null)
        //		{
        //			// Remove the new and take the old one.
        //			customer.RemoveAddress(customer.BillingAddress);
        //			customer.BillingAddress = existingAddress;

        //			try
        //			{
        //				_addressService.DeleteAddress(newAddressId);
        //			}
        //			catch (Exception exception)
        //			{
        //				exception.Dump();
        //			}
        //		}
        //	}

        //	customer.ShippingAddress = (isShippable ? customer.BillingAddress : null);

        //	return true;
        //}

        private AmazonPayData GetDetails(AuthorizeResponse response)
        {
            var data = new AmazonPayData();

            data.MessageType     = "GetAuthorizationDetails";
            data.MessageId       = response.GetRequestId();
            data.AuthorizationId = response.GetAuthorizationId();
            data.ReferenceId     = response.GetAuthorizationReferenceId();

            var ids = response.GetCaptureIdList();

            if (ids.Any())
            {
                data.CaptureId = ids.First();
            }

            data.Fee = new AmazonPayPrice(response.GetAuthorizationFee(), response.GetAuthorizationFeeCurrencyCode());
            data.AuthorizedAmount  = new AmazonPayPrice(response.GetAuthorizationAmount(), response.GetAuthorizationAmountCurrencyCode());
            data.CapturedAmount    = new AmazonPayPrice(response.GetCapturedAmount(), response.GetCapturedAmountCurrencyCode());
            data.CaptureNow        = response.GetCaptureNow();
            data.Creation          = response.GetCreationTimestamp();
            data.Expiration        = response.GetExpirationTimestamp();
            data.ReasonCode        = response.GetReasonCode();
            data.ReasonDescription = response.GetReasonDescription();
            data.State             = response.GetAuthorizationState();
            data.StateLastUpdate   = response.GetLastUpdateTimestamp();

            return(data);
        }
コード例 #2
0
        private AmazonPayData GetDetails(RefundResponse response)
        {
            var data = new AmazonPayData();

            data.MessageType       = "GetRefundDetails";
            data.MessageId         = response.GetRequestId();
            data.ReferenceId       = response.GetRefundReferenceId();
            data.Creation          = response.GetCreationTimestamp();
            data.Fee               = new AmazonPayPrice(response.GetRefundFee(), response.GetRefundFeeCurrencyCode());
            data.RefundedAmount    = new AmazonPayPrice(response.GetRefundAmount(), response.GetRefundAmountCurrencyCode());
            data.ReasonCode        = response.GetReasonCode();
            data.ReasonDescription = response.GetReasonDescription();
            data.State             = response.GetRefundState();
            data.StateLastUpdate   = response.GetLastUpdateTimestamp();

            return(data);
        }
コード例 #3
0
        private string ToInfoString(AmazonPayData data)
        {
            var sb = new StringBuilder();

            try
            {
                var strings = _services.Localization.GetResource("Plugins.Payments.AmazonPay.MessageStrings").SplitSafe(";");
                var state   = data.State.Grow(data.ReasonCode, " ");

                if (data.ReasonDescription.HasValue())
                {
                    state = $"{state} ({data.ReasonDescription})";
                }

                sb.AppendLine($"{strings.SafeGet((int)AmazonPayMessage.MessageTyp)}: {data.MessageType.NaIfEmpty()}");
                sb.AppendLine($"{strings.SafeGet((int)AmazonPayMessage.State)}: {state}");

                var stateDate = _dateTimeHelper.ConvertToUserTime(data.StateLastUpdate, DateTimeKind.Utc);
                sb.AppendLine($"{strings.SafeGet((int)AmazonPayMessage.StateUpdate)}: {stateDate.ToString()}");

                sb.AppendLine($"{strings.SafeGet((int)AmazonPayMessage.MessageId)}: {data.MessageId.NaIfEmpty()}");

                if (data.AuthorizationId.HasValue())
                {
                    sb.AppendLine($"{strings.SafeGet((int)AmazonPayMessage.AuthorizationID)}: {data.AuthorizationId}");
                }

                if (data.CaptureId.HasValue())
                {
                    sb.AppendLine($"{strings.SafeGet((int)AmazonPayMessage.CaptureID)}: {data.CaptureId}");
                }

                if (data.RefundId.HasValue())
                {
                    sb.AppendLine($"{strings.SafeGet((int)AmazonPayMessage.RefundID)}: {data.RefundId}");
                }

                sb.AppendLine($"{strings.SafeGet((int)AmazonPayMessage.ReferenceID)}: {data.ReferenceId.NaIfEmpty()}");

                if (data.Fee != null && data.Fee.Amount != decimal.Zero)
                {
                    var signed = data.MessageType.IsCaseInsensitiveEqual("RefundNotification") || data.MessageType.IsCaseInsensitiveEqual("GetRefundDetails") ? "-" : "";
                    sb.AppendLine($"{strings.SafeGet((int)AmazonPayMessage.Fee)}: {signed}");
                }

                if (data.AuthorizedAmount != null && data.AuthorizedAmount.Amount != decimal.Zero)
                {
                    sb.AppendLine($"{strings.SafeGet((int)AmazonPayMessage.AuthorizedAmount)}: {data.AuthorizedAmount.ToString()}");
                }

                if (data.CapturedAmount != null && data.CapturedAmount.Amount != decimal.Zero)
                {
                    sb.AppendLine($"{strings.SafeGet((int)AmazonPayMessage.CapturedAmount)}: {data.CapturedAmount.ToString()}");
                }

                if (data.RefundedAmount != null && data.RefundedAmount.Amount != decimal.Zero)
                {
                    sb.AppendLine($"{strings.SafeGet((int)AmazonPayMessage.RefundedAmount)}: {data.RefundedAmount.ToString()}");
                }

                if (data.CaptureNow.HasValue)
                {
                    sb.AppendLine($"{strings.SafeGet((int)AmazonPayMessage.CaptureNow)}: {data.CaptureNow.Value.ToString()}");
                }

                var creationDate = _dateTimeHelper.ConvertToUserTime(data.Creation, DateTimeKind.Utc);
                sb.AppendLine($"{strings.SafeGet((int)AmazonPayMessage.Creation)}: {creationDate.ToString()}");

                if (data.Expiration.HasValue)
                {
                    var expirationDate = _dateTimeHelper.ConvertToUserTime(data.Expiration.Value, DateTimeKind.Utc);
                    sb.AppendLine($"{strings.SafeGet((int)AmazonPayMessage.Expiration)}: {expirationDate.ToString()}");
                }
            }
            catch (Exception exception)
            {
                exception.Dump();
            }

            return(sb.ToString());
        }