-
Notifications
You must be signed in to change notification settings - Fork 0
/
courseEnrol.go
129 lines (111 loc) · 7.12 KB
/
courseEnrol.go
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
package axcelerate
import (
"encoding/json"
"fmt"
"strconv"
)
type Enrol struct {
InvoiceID int `json:"InvoiceID"`
ContactID int `json:"ContactID"`
LearnerID int `json:"LearnerID"`
Amount int `json:"Amount"`
}
/*
CourseEnrol Enrols a Contact in an Activity Instance. This method sends notifications to the student, payer, and administrator. Enrolments into linked E-Learning will be scheduled and processed by the system later.
Request Parameters (passed as a map[string]string):
--------------------------------------------
Header Type Required Default Description
contactID numeric true The ID of the Contact you are enrolling.
instanceID numeric true The ID of the Activity Instance you are enrolling the contact into.
type string true The type of the activity. w = workshop, p = accredited program, el = e-learning.
tentative boolean false Enrol the Contact as Tentative.
payerID numeric false The ID of the Contact that is paying for the course. Defaults to the student (contactID) if omitted.
invoiceID numeric false 0 The ID of the invoice created for this Contact (during payment) or the ID of the invoice to add this enrolment to. Defaults to 0 if omitted.
PONumber string false The Purchase Order Number for a new invoice generated during this booking.
generateInvoice boolean false true Determines if a new invoice should be generated for this booking (only works if the course cost > $0).
lockInvoiceItems boolean false true If a new invoice is generated, determines if items are locked (required before payments can be applied).
archiveInvoice boolean false false Determines if the new invoice is completely locked and archived (prevents future modifications).
forceBooking boolean false false Forces the enrolment even if it is closed.
bookOnDefaultWorkshops boolean false true (type=p) Automatically book into workshops linked to the program’s units. Errors if multiple workshops are linked.
syncDatesWithWorkshop boolean false true (type=p) Sync unit start/end dates with linked workshops.
syncUOCdates boolean false false (type=p) Sync Unit of Competency dates with Unit of Study dates (only if syncDatesWithWorkshop is false).
syncWithClassSchedule boolean false false (type=p) Offset unit start/end dates based on commencement date and class schedule.
applyGST (DEPRECATED) boolean false false (type=p) Determines if cost includes GST (normally GST-free for accredited training).
GST_type numeric false Specifies GST type: 0 = no GST, 1 = GST included.
autoGrantCT boolean false false Automatically set subject outcome to CT for existing competencies in accredited bookings.
dateCommenced date false (type=p) The enrolment commencement date.
dateCompletionExpected date false (type=p) The expected completion date (ignored if using syncWithClassSchedule).
suppressNotifications boolean false false Suppresses all booking notification emails.
sendAdminNotification boolean false false Sends admin notification even if suppressNotifications is true.
blockAdminNotification boolean false false Explicitly blocks admin notifications.
useRegistrationFormDefaults boolean false false (type=p) Applies default registration form values for accredited program bookings.
StudyReasonID numeric false AVETMISS Study Reason (for accredited enrolments).
FundingNational numeric false AVETMISS Funding Source - National (for accredited enrolments).
marketingAgentContactID numeric false The ID of the marketing agent associated with the enrolment.
serviceDate string false The service date for the invoice item.
cost numeric false Discounted cost for the enrolment.
commencingProgramCohortIdentifiers string false Commencing program cohort ID (first 6 characters considered).
discountIDList string false A list of valid discountIDs for this booking (required if 'cost' is provided).
customField_[variableName] string false Custom field value for the enrolment (comma-delimited or JSON array for multiple values).
FundingState string false AVETMISS Funding Source - State (for accredited enrolments).
PSTACDateVIC date false (type=p) Program Supervised Teaching Activity Completion Date (for Victorian reporting).
commencedWhileAtSchool boolean false (type=p) Indicates if the enrolment commenced while at school (for Victorian reporting).
Returns:
--------------------------------------------
- Enrol: Struct containing the enrolment details.
- *Response: API response metadata.
- error: Error object if any issue occurs during the request.
Example Usage:
--------------------------------------------
params := map[string]string{
"contactID": "123",
"instanceID": "456",
"type": "w",
"payerID": "789",
"generateInvoice": "true",
}
enrolment, resp, err := coursesService.CourseEnrol(params)
if err != nil {
log.Fatalf("Error enrolling contact: %v", err)
}
fmt.Printf("Enrolment ID: %d\n", enrolment.InvoiceID)
*/
func (s *CoursesService) CourseEnrol(parms map[string]string) (*Enrol, *Response, error) {
var obj enrolEnteral
if len(parms) == 0 {
parms = map[string]string{}
}
resp, err := do(s.client, "POST", Params{parms: parms, u: "/course/enrol"}, obj)
if err != nil {
return nil, resp, err
}
err = json.Unmarshal([]byte(resp.Body), &obj)
if err != nil {
return nil, resp, fmt.Errorf("failed to unmarshal response: %w", err)
}
// Convert enrolEnteral to Enrol
enrol, err := convertEnteralToEnrol(obj)
if err != nil {
return nil, resp, fmt.Errorf("failed to convert enrol: %w", err)
}
return enrol, resp, nil
}
// enrolEnteral is the internal data structure for processing enrolments
type enrolEnteral struct {
InvoiceID int `json:"INVOICEID"`
ContactID int `json:"CONTACTID"`
LearnerID int `json:"LEARNERID"`
Amount string `json:"AMOUNT"`
}
func convertEnteralToEnrol(internalEnrol enrolEnteral) (*Enrol, error) {
amount, err := strconv.Atoi(internalEnrol.Amount) // Convert string to int
if err != nil {
return nil, fmt.Errorf("invalid amount value: %v", err)
}
return &Enrol{
InvoiceID: internalEnrol.InvoiceID,
ContactID: internalEnrol.ContactID,
LearnerID: internalEnrol.LearnerID,
Amount: amount,
}, nil
}