Skip to content

Commit 5432a17

Browse files
committed
Fields mapping and updated workflow with form data
1 parent 47cac40 commit 5432a17

File tree

12 files changed

+367
-24
lines changed

12 files changed

+367
-24
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
function CustomerDetailsMapperController($scope, $routeParams, pickerResource, notificationsService) {
2+
3+
var vm = this;
4+
5+
init();
6+
7+
vm.addMapping = function () {
8+
9+
if (vm.mappings.find(p => p.customerProperty === vm.selectedCustomerProperty)) {
10+
notificationsService.warning("Customer property is already mapped.");
11+
return;
12+
}
13+
14+
vm.mappings.push({
15+
customerProperty: vm.selectedCustomerProperty,
16+
field: vm.fields.find(p => p.id === vm.selectedField)
17+
});
18+
19+
$scope.setting.value = JSON.stringify(vm.mappings);
20+
21+
vm.selectedCustomerProperty = "";
22+
vm.selectedField = "";
23+
}
24+
25+
vm.deleteMapping = function(index) {
26+
vm.mappings.splice(index);
27+
28+
$scope.setting.value = JSON.stringify(vm.mappings);
29+
}
30+
31+
function init() {
32+
vm.customerProperties = ["Email", "FirstName", "LastName", "Phone", "Address", "ZipCode", "City", "State", "Country"];
33+
34+
vm.fields = [];
35+
vm.selectedCustomerProperty = "";
36+
vm.selectedField = "";
37+
38+
var formId = $routeParams.id;
39+
40+
if (formId !== -1) {
41+
pickerResource.getAllFields($routeParams.id).then(function (response) {
42+
vm.fields = response.data;
43+
});
44+
}
45+
46+
vm.mappings = $scope.setting.value
47+
? JSON.parse($scope.setting.value)
48+
: [];
49+
}
50+
}
51+
52+
angular.module("umbraco")
53+
.controller("UmbracoForms.Integrations.Commerce.eMerchantPay.CustomerDetailsMapperController", CustomerDetailsMapperController);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<div ng-controller="UmbracoForms.Integrations.Commerce.eMerchantPay.CustomerDetailsMapperController as vm">
2+
3+
<div>
4+
<select ng-model="vm.selectedCustomerProperty">
5+
<option value="">Select customer property</option>
6+
<option ng-repeat="property in vm.customerProperties" value="{{ property }}">{{ property }}</option>
7+
</select>
8+
<select ng-model="vm.selectedField">
9+
<option value="">Select field</option>
10+
<option ng-repeat="field in vm.fields" value="{{ field.id }}">{{ field.value }}</option>
11+
</select>
12+
</div>
13+
14+
<div class="mt2">
15+
<umb-button type="button" class="mt2"
16+
action="vm.addMapping()"
17+
label="Add mapping"
18+
disabled="vm.selectedCustomerProperty.length === 0 || vm.selectedField.length === 0">
19+
</umb-button>
20+
</div>
21+
22+
<div class="umb-forms-mappings mt2" ng-if="vm.mappings.length > 0">
23+
24+
<div class="umb-forms-mapping-header">
25+
<div class="umb-forms-mapping-field -no-margin-left">Property</div>
26+
<div class="umb-forms-mapping-field">Field</div>
27+
<div class="umb-forms-mapping-remove -no-margin-right"></div>
28+
</div>
29+
30+
<div class="umb-forms-mapping" ng-repeat="mapping in vm.mappings">
31+
<div class="umb-forms-mapping-field -no-margin-left">{{ mapping.customerProperty }}</div>
32+
<div class="umb-forms-mapping-field">{{ mapping.field.value }}</div>
33+
<div class="umb-forms-mapping-remove -no-margin-right">
34+
<a href="" ng-click="vm.deleteMapping($index)">
35+
<i class="icon-trash"></i>
36+
</a>
37+
</div>
38+
</div>
39+
</div>
40+
41+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"javascript": [
3+
"~/App_Plugins/UmbracoForms.Integrations/Commerce/eMerchantPay/customer-details-mapper.controller.js"
4+
],
5+
"css": [ "" ]
6+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
using Umbraco.Forms.Core.Persistence.Dtos;
6+
using Umbraco.Forms.Integrations.Commerce.EMerchantPay.Models.Dtos;
7+
8+
namespace Umbraco.Forms.Integrations.Commerce.EMerchantPay.Builders
9+
{
10+
public class MappingBuilder
11+
{
12+
protected MappingValues Values = new MappingValues();
13+
14+
public MappingBuilder SetValues(Record record, List<Mapping> mappings)
15+
{
16+
Values.Email = GetValue(nameof(MappingValues.Email), record, mappings);
17+
Values.FirstName = GetValue(nameof(MappingValues.FirstName), record, mappings);
18+
Values.LastName = GetValue(nameof(MappingValues.LastName), record, mappings);
19+
Values.Address = GetValue(nameof(MappingValues.Address), record, mappings);
20+
Values.ZipCode = GetValue(nameof(MappingValues.ZipCode), record, mappings);
21+
Values.City = GetValue(nameof(MappingValues.City), record, mappings);
22+
Values.State = GetValue(nameof(MappingValues.State), record, mappings);
23+
Values.Country = GetValue(nameof(MappingValues.Country), record, mappings);
24+
Values.Phone = GetValue(nameof(MappingValues.Phone), record, mappings);
25+
26+
return this;
27+
}
28+
29+
public MappingBuilder SetSuccessUrl()
30+
{
31+
return this;
32+
}
33+
34+
private string GetValue(string property, Record record, List<Mapping> mappings)
35+
{
36+
var key = mappings.First(p => p.CustomerProperty == nameof(property)).Field.Id;
37+
return record.RecordFields[Guid.Parse(key)].ValuesAsString();
38+
}
39+
40+
public MappingValues Build() => Values;
41+
}
42+
}

src/Umbraco.Forms.Integrations.Commerce.EMerchantPay/Constants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ public class Constants
55
{
66
public const string WorkflowId = "b2731255-2e48-4345-9ae5-aaf5b8bfb10a";
77

8+
public const int RequiredMappingsNo = 9;
9+
810
public static class Configuration
911
{
1012
public const string Settings = "Umbraco:Forms:Integrations:Commerce:eMerchantPay:Settings";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Collections.Generic;
2+
3+
using Newtonsoft.Json;
4+
5+
using Umbraco.Forms.Integrations.Commerce.EMerchantPay.Models.Dtos;
6+
7+
namespace Umbraco.Forms.Integrations.Commerce.EMerchantPay.ExtensionMethods
8+
{
9+
public static class CustomerDetailsMappingsExtensions
10+
{
11+
/// <summary>
12+
/// Parse consumer mappings and validate the correct number of mappings
13+
/// </summary>
14+
/// <param name="serializedDetails"></param>
15+
/// <param name="mappings"></param>
16+
/// <returns></returns>
17+
public static bool TryParseMappings(this string serializedDetails, out List<Mapping> mappings)
18+
{
19+
mappings = new List<Mapping>();
20+
21+
if (string.IsNullOrEmpty(serializedDetails)) return false;
22+
23+
mappings = JsonConvert.DeserializeObject<List<Mapping>>(serializedDetails);
24+
25+
return mappings.Count == Constants.RequiredMappingsNo;
26+
}
27+
}
28+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+

2+
namespace Umbraco.Forms.Integrations.Commerce.EMerchantPay.ExtensionMethods
3+
{
4+
public static class StringExtensions
5+
{
6+
public static bool IsContentValid(this string str, string type, out string error)
7+
{
8+
bool isValid = !string.IsNullOrEmpty(str) && str != "null";
9+
10+
error = isValid ? string.Empty : $"{type} field is required";
11+
12+
return isValid;
13+
}
14+
}
15+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Umbraco.Forms.Integrations.Commerce.EMerchantPay.Models.Dtos
4+
{
5+
public class Mapping
6+
{
7+
[JsonProperty("customerProperty")]
8+
public string CustomerProperty { get; set; }
9+
10+
[JsonProperty("field")]
11+
public MappingField Field { get; set; }
12+
}
13+
14+
public class MappingField
15+
{
16+
[JsonProperty("id")]
17+
public string Id { get; set; }
18+
19+
[JsonProperty("value")]
20+
public string Value { get; set; }
21+
}
22+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+

2+
namespace Umbraco.Forms.Integrations.Commerce.EMerchantPay.Models.Dtos
3+
{
4+
public class MappingValues
5+
{
6+
public string FirstName { get; set; }
7+
8+
public string LastName { get; set; }
9+
10+
public string Address { get; set; }
11+
12+
public string ZipCode { get; set; }
13+
14+
public string City { get; set; }
15+
16+
public string State { get; set; }
17+
18+
public string Country { get; set; }
19+
20+
public string Email { get; set; }
21+
22+
public string Phone { get; set; }
23+
}
24+
}

src/Umbraco.Forms.Integrations.Commerce.EMerchantPay/Models/Dtos/PaymentDto.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,8 @@ public class PaymentDto : ResponseDto
4646

4747
[XmlElement("return_cancel_url")]
4848
public string ReturnCancelUrl { get; set; }
49+
50+
[XmlElement("redirect_url")]
51+
public string RedirectUrl { get; set; }
4952
}
5053
}

0 commit comments

Comments
 (0)