-
Notifications
You must be signed in to change notification settings - Fork 1
/
DHLCreateShipment.cs
173 lines (138 loc) · 5.44 KB
/
DHLCreateShipment.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using Microsoft.AspNetCore.Http;
using Nop.Core;
using Nop.Core.Domain.Shipping;
<<<<<<< HEAD
using Nop.Plugin.Shipping.DHL.Domain;
using Nop.Plugin.Shipping.DHL.Services;
using Nop.Services.Cms;
=======
using Nop.Plugin.Shipping.DHL.Services;
>>>>>>> 67aab8c77e0c8f99bb3f15d7ceb45bc156150e5f
using Nop.Services.Configuration;
using Nop.Services.Plugins;
using Nop.Services.Shipping;
using Nop.Services.Shipping.Tracking;
<<<<<<< HEAD
using Nop.Web.Framework.Infrastructure;
=======
>>>>>>> 67aab8c77e0c8f99bb3f15d7ceb45bc156150e5f
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Nop.Plugin.Shipping.DHL
{
<<<<<<< HEAD
public class DHLCreateShipment : BasePlugin, IShippingRateComputationMethod, IWidgetPlugin
=======
public class DHLCreateShipment : BasePlugin, IShippingRateComputationMethod
>>>>>>> 67aab8c77e0c8f99bb3f15d7ceb45bc156150e5f
{
#region Fields
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ISettingService _settingService;
private readonly IWebHelper _webHelper;
private readonly DHLService _dhlService;
private readonly DHLStandardHttpClient _dhlHttpClient;
#endregion
#region Ctor
public DHLCreateShipment(
IHttpContextAccessor httpContextAccessor,
IWebHelper webHelper,
ISettingService settingService,
DHLService dhlService,
DHLStandardHttpClient dhlHttpClient)
{
_httpContextAccessor = httpContextAccessor;
_webHelper = webHelper;
_settingService = settingService;
_dhlService = dhlService;
_dhlHttpClient = dhlHttpClient;
}
#endregion
#region Methods
public GetShippingOptionResponse GetShippingOptions(GetShippingOptionRequest getShippingOptionRequest)
{
if (getShippingOptionRequest == null)
throw new ArgumentNullException(nameof(getShippingOptionRequest));
if (!getShippingOptionRequest.Items?.Any() ?? true)
return new GetShippingOptionResponse { Errors = new[] { "No shipment items" } };
if (getShippingOptionRequest.ShippingAddress?.CountryId == null)
return new GetShippingOptionResponse { Errors = new[] { "Shipping address is not set" } };
<<<<<<< HEAD
List<CapabilitesOptions.Options> capabilitesOptions = new List<CapabilitesOptions.Options>
{
CapabilitesOptions.Options.DOOR,
CapabilitesOptions.Options.NBB
};
var capabilites = _dhlHttpClient.CapabilitesBuilder(
fromCountry: CountryCode.ISO.NL, toCountry: CountryCode.ISO.NL,
parcelType: ParcelType.Parcel.SMALL, capabilitiesOptions: capabilitesOptions,
"9721TH", "5705CL", "Helmond").GetAwaiter().GetResult();
return _dhlService.GetShippingOptionResponse(getShippingOptionRequest);
=======
//string accessTokenCookieValue = _httpContextAccessor.HttpContext.Request.Cookies["accessToken"];
//string refreshTokenCookieValue = _httpContextAccessor.HttpContext.Request.Cookies["refreshToken"];
var options = _dhlService.GetShippingOptionResponse(getShippingOptionRequest);
return new GetShippingOptionResponse();
>>>>>>> 67aab8c77e0c8f99bb3f15d7ceb45bc156150e5f
}
public decimal? GetFixedRate(GetShippingOptionRequest getShippingOptionRequest)
{
return null;
}
public override void Install()
{
//settings
_settingService.SaveSetting(new DHLSettings
{
UseSandbox = true,
UserID = " ",
Key = " ",
AccountNumber = " ",
LocationFinderKey = " ",
ApiUrl = "https://api-gw.dhlparcel.nl"
});
base.Install();
}
/// <summary>
/// Uninstall plugin
/// </summary>
public override void Uninstall()
{
//settings
_settingService.DeleteSetting<DHLSettings>();
base.Uninstall();
}
/// <summary>
/// Gets a configuration page URL
/// </summary>
public override string GetConfigurationPageUrl()
{
return $"{_webHelper.GetStoreLocation()}Admin/DHLShipping/Configure";
}
public IList<string> GetWidgetZones()
{
return new List<string>
{
PublicWidgetZones.OpCheckoutShippingMethodBottom
};
}
public string GetWidgetViewComponentName(string widgetZone)
{
if (widgetZone == null)
throw new ArgumentNullException(nameof(widgetZone));
return "DHLShipmentWidget";
}
#endregion
#region Utilities
public ShippingRateComputationMethodType ShippingRateComputationMethodType => ShippingRateComputationMethodType.Realtime;
public IShipmentTracker ShipmentTracker => new DHLShipmentTracker(_dhlService);
public bool HideInWidgetList => false;
#endregion
#region Utilities
public ShippingRateComputationMethodType ShippingRateComputationMethodType => ShippingRateComputationMethodType.Realtime;
public IShipmentTracker ShipmentTracker => new DHLShipmentTracker(_dhlService);
#endregion
}
}