@@ -35,6 +35,15 @@ protocol ZendeskManagerProtocol: SupportManagerAdapter {
35
35
func showNewWCPayRequestIfPossible( from controller: UIViewController , with sourceTag: String ? )
36
36
func showNewWCPayRequestIfPossible( from controller: UIViewController )
37
37
38
+ /// Creates a support request using the API-Providers SDK.
39
+ ///
40
+ func createSupportRequest( formID: Int64 ,
41
+ customFields: [ Int64 : String ] ,
42
+ tags: [ String ] ,
43
+ subject: String ,
44
+ description: String ,
45
+ onCompletion: @escaping ( Result < Void , Error > ) -> Void )
46
+
38
47
var zendeskEnabled : Bool { get }
39
48
func userSupportEmail( ) -> String ?
40
49
func showHelpCenter( from controller: UIViewController )
@@ -45,6 +54,18 @@ protocol ZendeskManagerProtocol: SupportManagerAdapter {
45
54
func fetchSystemStatusReport( )
46
55
func initialize( )
47
56
func reset( )
57
+
58
+ /// To Refactor: These methods would end-up living outside this class. Exposing them here temporarily.
59
+ /// https://github.com/woocommerce/woocommerce-ios/issues/8795
60
+ ///
61
+ func formID( ) -> Int64
62
+ func wcPayFormID( ) -> Int64
63
+
64
+ func generalTags( ) -> [ String ]
65
+ func wcPayTags( ) -> [ String ]
66
+
67
+ func generalCustomFields( ) -> [ Int64 : String ]
68
+ func wcPayCustomFields( ) -> [ Int64 : String ]
48
69
}
49
70
50
71
struct NoZendeskManager : ZendeskManagerProtocol {
@@ -68,6 +89,15 @@ struct NoZendeskManager: ZendeskManagerProtocol {
68
89
// no-op
69
90
}
70
91
92
+ func createSupportRequest( formID: Int64 ,
93
+ customFields: [ Int64 : String ] ,
94
+ tags: [ String ] ,
95
+ subject: String ,
96
+ description: String ,
97
+ onCompletion: @escaping ( Result < Void , Error > ) -> Void ) {
98
+ // no-op
99
+ }
100
+
71
101
var zendeskEnabled = false
72
102
73
103
func userSupportEmail( ) -> String ? {
@@ -107,6 +137,35 @@ struct NoZendeskManager: ZendeskManagerProtocol {
107
137
}
108
138
}
109
139
140
+ /// To Refactor: These methods would end-up living outside this class. Exposing them here temporarily.
141
+ /// https://github.com/woocommerce/woocommerce-ios/issues/8795
142
+ ///
143
+ extension NoZendeskManager {
144
+ func formID( ) -> Int64 {
145
+ . zero
146
+ }
147
+
148
+ func wcPayFormID( ) -> Int64 {
149
+ . zero
150
+ }
151
+
152
+ func generalTags( ) -> [ String ] {
153
+ [ ]
154
+ }
155
+
156
+ func wcPayTags( ) -> [ String ] {
157
+ [ ]
158
+ }
159
+
160
+ func generalCustomFields( ) -> [ Int64 : String ] {
161
+ [ : ]
162
+ }
163
+
164
+ func wcPayCustomFields( ) -> [ Int64 : String ] {
165
+ [ : ]
166
+ }
167
+ }
168
+
110
169
extension NoZendeskManager : SupportManagerAdapter {
111
170
/// Executed whenever the app receives a Push Notifications Token.
112
171
///
@@ -361,6 +420,25 @@ final class ZendeskManager: NSObject, ZendeskManagerProtocol {
361
420
}
362
421
}
363
422
423
+ /// Creates a support request using the API-Providers SDK.
424
+ ///
425
+ func createSupportRequest( formID: Int64 ,
426
+ customFields: [ Int64 : String ] ,
427
+ tags: [ String ] ,
428
+ subject: String ,
429
+ description: String ,
430
+ onCompletion: @escaping ( Result < Void , Error > ) -> Void ) {
431
+
432
+ let requestProvider = ZDKRequestProvider ( )
433
+ let request = createAPIRequest ( formID: formID, customFields: customFields, tags: tags, subject: subject, description: description)
434
+ requestProvider. createRequest ( request) { _, error in
435
+ if let error {
436
+ return onCompletion ( . failure( error) )
437
+ }
438
+ onCompletion ( . success( ( ) ) )
439
+ }
440
+ }
441
+
364
442
/// Displays the Zendesk Request List view from the given controller, allowing user to access their tickets.
365
443
///
366
444
func showTicketListIfPossible( from controller: UIViewController , with sourceTag: String ? ) {
@@ -457,6 +535,47 @@ final class ZendeskManager: NSObject, ZendeskManagerProtocol {
457
535
}
458
536
}
459
537
538
+ /// To Refactor: These methods would end-up living outside this class. Exposing them here temporarily.
539
+ /// https://github.com/woocommerce/woocommerce-ios/issues/8795
540
+ ///
541
+ extension ZendeskManager {
542
+ func formID( ) -> Int64 {
543
+ createRequest ( supportSourceTag: nil ) . ticketFormID? . int64Value ?? . zero
544
+ }
545
+
546
+ func wcPayFormID( ) -> Int64 {
547
+ createWCPayRequest ( supportSourceTag: nil ) . ticketFormID? . int64Value ?? . zero
548
+ }
549
+
550
+ func generalTags( ) -> [ String ] {
551
+ getTags ( supportSourceTag: nil )
552
+ }
553
+
554
+ func wcPayTags( ) -> [ String ] {
555
+ getWCPayTags ( supportSourceTag: nil )
556
+ }
557
+
558
+ func generalCustomFields( ) -> [ Int64 : String ] {
559
+ // Extracts the custom fields from the `createRequest` method
560
+ createRequest ( supportSourceTag: nil ) . customFields. reduce ( [ : ] ) { dict, field in
561
+ guard let value = field. value as? String else { return dict } // Guards that all values are string
562
+ var mutableDict = dict
563
+ mutableDict [ field. fieldId] = value
564
+ return mutableDict
565
+ }
566
+ }
567
+
568
+ func wcPayCustomFields( ) -> [ Int64 : String ] {
569
+ // Extracts the custom fields from the `createWCPayRequest` method.
570
+ createWCPayRequest ( supportSourceTag: nil ) . customFields. reduce ( [ : ] ) { dict, field in
571
+ guard let value = field. value as? String else { return dict } // Guards that all values are string
572
+ var mutableDict = dict
573
+ mutableDict [ field. fieldId] = value
574
+ return mutableDict
575
+ }
576
+ }
577
+ }
578
+
460
579
// MARK: - Push Notifications
461
580
//
462
581
extension ZendeskManager {
@@ -749,6 +868,18 @@ private extension ZendeskManager {
749
868
return requestConfig
750
869
}
751
870
871
+ /// Creates a Zendesk Request to be consumed by a Request Provider.
872
+ ///
873
+ func createAPIRequest( formID: Int64 , customFields: [ Int64 : String ] , tags: [ String ] , subject: String , description: String ) -> ZDKCreateRequest {
874
+ let request = ZDKCreateRequest ( )
875
+ request. ticketFormId = formID as NSNumber
876
+ request. customFields = customFields. map { CustomField ( fieldId: $0, value: $1) }
877
+ request. tags = tags
878
+ request. subject = subject
879
+ request. requestDescription = description
880
+ return request
881
+ }
882
+
752
883
// MARK: - View
753
884
//
754
885
func showZendeskView( _ zendeskView: UIViewController , from controller: UIViewController ) {
0 commit comments