Subversion Repositories PEEPS

Rev

Rev 6 | Rev 24 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6 Rev 22
Line 15... Line 15...
15
$ENV{HTTPS} = 'ON' if $ENV{SERVER_NAME} =~ /^peeps/;
15
$ENV{HTTPS} = 'ON' if $ENV{SERVER_NAME} =~ /^peeps/;
Line 16... Line 16...
16
 
16
 
17
my $cookie_string = authenticate (1) || die;
17
my $cookie_string = authenticate (1) || die;
18
my ($EML, $PWD, $LVL) = split /&/, $cookie_string;
18
my ($EML, $PWD, $LVL) = split /&/, $cookie_string;
-
 
19
my $user = $ORCUSER;
19
my $user = $ORCUSER;
20
my $RENEWAL_WINDOW = 900;   ### <-----------  CHANGE BACK AFTER TESTING!
Line 20... Line 21...
20
#my $activated = $ORCUSER->{access};
21
#my $activated = $ORCUSER->{access};
21
 
22
 
22
use DateTime;
-
 
Line -... Line 23...
-
 
23
use DateTime;
23
my $dt = DateTime->today;
24
my $dt = DateTime->today()->strftime ('%Y-%m-%d');
-
 
25
 
24
$dt =~ s/T00\:00\:00$//;
26
 
25
 
27
## Which Policy ID is being requested?
26
my ($eligible, $daysremaining);
28
##
27
$user->{policy} = isPersonCovered ($user->{id});
29
my $policy_id = WebDB::trim scalar param ("policy") // "ERROR";
28
if ($user->{policy}) {
30
my $policy = getPolicyByID ($policy_id) // {};
29
  $daysremaining = remainingPolicyDays ($user->{id}, $user->{policy});
-
 
30
  if ($daysremaining <= 90) {
-
 
31
    $eligible = "renew";
31
if ($policy_id ne $policy->{id} or !$policy->{active}) {
32
  } 
32
  ERROR ("Policy ID [$policy_id] not found",
Line -... Line 33...
-
 
33
         "It's unclear what type of insurance you're attempting to purchase.",
-
 
34
         "Viewed Attestation page without valid policy_id.");
-
 
35
}
-
 
36
 
-
 
37
 
-
 
38
## We have a valid Policy ID, check purchase eligibility.
-
 
39
##
-
 
40
my ($eligible, $daysremaining, $active_policy, $league_id, $league_name);
-
 
41
 
-
 
42
if ($policy->{type} eq "league") {
-
 
43
  ## If it's a League Policy Type, then get the Leauge ID too.
33
} else {
44
  ##
-
 
45
  $league_id = $policy->{type} eq "league" ? WebDB::trim scalar param ("league") // undef : undef;
-
 
46
  $league_name = $league_id =~ /^\d+$/ ? getLeagueName ($league_id) : undef;
-
 
47
  
34
  $eligible = "new";
48
  if (!$league_name) {
-
 
49
    ## If there's no leauge_name, it's not a valid league...
-
 
50
    ERROR ("League ID [$league_id] not found",
-
 
51
           "It's unclear which league you are attempting to cover.",
35
}
52
           "Viewed Attestation page for league coverage without valid league_id.");
-
 
53
  }
-
 
54
  
-
 
55
  ## Only Leauge Admins should be purchasing league type polcies
-
 
56
  use tableViewer qw/ notInArray /;
-
 
57
  if (notInArray ($league_id, isLeagueAdmin ($user->{person_id}))) {
-
 
58
    ERROR ("Not a League Admin [$league_id]",
-
 
59
           "You must be a League Admin to purchase insurance for the league.",
-
 
60
           "Viewed Attestation page for league coverage but not a league admin.");
-
 
61
  }
-
 
62
  
-
 
63
  ## Check to see if this is a new purchase or within the renewal period.  If neither, eligible will be empty.
36
 
64
  $active_policy = isLeagueCovered ($league_id);
-
 
65
  if ($active_policy) {
-
 
66
    $daysremaining = remainingOrgPolicyDays ($league_id, $active_policy);
37
if (!$eligible) {
67
    if ($daysremaining <= $RENEWAL_WINDOW) {
-
 
68
      $eligible = "renew";
-
 
69
    } 
-
 
70
  } else {
-
 
71
    $eligible = "new";
-
 
72
  }
38
  print header (-cookie=>CGI::Cookie->new(-name=>'PEEPSAUTH',-value=>"$cookie_string"));
73
} elsif ($policy->{type} eq "personal") {
-
 
74
  if ($policy->{id} eq "4") { # They're trying to buy RollerCon Coverage...
-
 
75
    $active_policy = isPersonCovered ($user->{id}, '2026-07-11');
-
 
76
    if (!$active_policy) {
-
 
77
      ($active_policy) = $dbh->selectrow_array ("select id from coverage where policy_id = ? and person_id = ?", undef, 4, $user->{id});
-
 
78
    }
-
 
79
    
-
 
80
    ERROR ("Already Covered",
-
 
81
           "You are already covered for RollerCon 2026 by Policy $active_policy. No need to purchase.",
39
  printRCHeader("Atttestation");
82
           "Attempted to purchase RollerCon 2026 covereage but not needed") unless !$active_policy;
40
  print $h->close ("table");
83
    
41
  print $h->h2 ("Not Eligible for Renewal");
84
  } else {
-
 
85
    ## Check to see if this is a new purchase or within the renewal period.  If neither, eligible will be empty.
-
 
86
    $active_policy = isPersonCovered ($user->{id});
42
  print $h->div ({ style=>"max-width:450px;" }, "You're currently covered by policy $user->{policy}, which has $daysremaining days remaining. You can only renew within the last 90 days of your current policy.", "&nbsp;");
87
    if ($active_policy) {
-
 
88
      $daysremaining = remainingPolicyDays ($user->{id}, $active_policy);
-
 
89
      if ($daysremaining <= $RENEWAL_WINDOW) {
-
 
90
        $eligible = "renew";
-
 
91
      }
-
 
92
    } else {
-
 
93
      $eligible = "new";
-
 
94
    }
-
 
95
  }
-
 
96
} else {
43
  print $h->button ({onclick => "window.location.href='/';"}, "Home");
97
  ## If we're here, it means the policy type wasn't recognized...
Line -... Line 98...
-
 
98
  ERROR ("Something weird happened...",
-
 
99
         "The type of policy you attempted to puchase doesn't seem to exist.",
-
 
100
         "Viewed Attestation page for invalid policy type.");
-
 
101
}
-
 
102
 
-
 
103
ERROR ("Not Eligible for Renewal",
-
 
104
       "You".($policy->{type} eq "league" ? "r league is" : " are")." currently covered by policy $active_policy, which has $daysremaining days remaining. You can only renew within the last $RENEWAL_WINDOW days of your current policy.",
44
  print $h->close ("BODY", "HTML");
105
       "Viewed Attestation page but wasn't eligible to renew.") unless $eligible;
45
  logit ($user->{id}, "Viewed Attestation page but wasn't eligible to renew.");
106
 
46
  exit;
107
## Check to see if there is an abandoned checkout that needs to be completed...
47
}
108
my ($abandoned_checkout) = $policy->{type} eq "league" ?
48
 
109
      $dbh->selectrow_array ("select url from square_order where organization_id = ? and policy_id = ? and status = ? order by created desc limit 1", undef, $league_id, $policy->{id}, "DRAFT") :
49
my ($abandoned_checkout) = $dbh->selectrow_array ("select url from square_order where person_id = ? and status = ? order by created desc limit 1", undef, $user->{id}, "DRAFT");
110
      $dbh->selectrow_array ("select url from square_order where person_id = ? and policy_id = ? and status = ? order by created desc limit 1", undef, $user->{id}, $policy->{id}, "DRAFT") ;
50
if ($abandoned_checkout) {
111
if ($abandoned_checkout) {
Line -... Line 112...
-
 
112
  my $cgi = CGI->new();
-
 
113
  logit ($user->{id}, "Returned to abandoned $policy->{type} policy checkout.");
51
  my $cgi = CGI->new();
114
  print $cgi->redirect ($abandoned_checkout);
52
  logit ($user->{id}, "Returned to abandoned checkout.");
115
  exit;  
53
  print $cgi->redirect ($abandoned_checkout);
116
}
54
  exit;  
117
 
55
}
118
## Get the terms for attestion...
Line 56... Line 119...
56
 
119
my @terms = map { @{$_} } @{ $dbh->selectall_arrayref ("select term from attestation where id = ? order by attestation.index", undef, $policy->{attestation_id}) };
57
my $terms;
120
my $terms;
58
foreach (1..8) {
121
foreach (1..scalar @terms) {
59
  $terms++ if param ("Term".$_);
122
  $terms++ if param ("Term".$_);
60
}
123
}
61
my $esig = param ("esignature") // "";
124
my $esig = param ("esignature") // "";
62
 
125
 
Line 63... Line 126...
63
if ($terms == 8 and $esig =~ /^\w+$/) {
126
if ($terms == scalar @terms and $esig =~ /^\w+$/) {
64
  # All of the checkboxes were accepted and an eSignature was entered.
127
  # All of the checkboxes were accepted and an eSignature was entered.
Line 74... Line 137...
74
print $h->close ("table");
137
print $h->close ("table");
Line 75... Line 138...
75
 
138
 
Line 76... Line 139...
76
print $h->open ("form", { name => "Attestation", method => "post", action => url });
139
print $h->open ("form", { name => "Attestation", method => "post", action => url });
-
 
140
 
-
 
141
print $h->input ( { type => "hidden", name => "timezone", id => "TZFIELD", value => "" } );
Line 77... Line -...
77
 
-
 
Line 78... Line 142...
78
print $h->input ( { type => "hidden", name => "timezone", id => "TZFIELD", value => "" } );
142
print $h->input ( { type => "hidden", name => "policy", value => $policy_id } );
Line -... Line 143...
-
 
143
print $h->input ( { type => "hidden", name => "league", value => $league_id } ) unless !$league_id;
79
 
144
 
Line -... Line 145...
-
 
145
 
-
 
146
print $h->div ({ class=>"error" }, "&nbsp;", "ERROR: You must agree to each term to continue.") if $terms and $terms < scalar @terms;
-
 
147
 
-
 
148
print $h->h2 ("Policy Details");
-
 
149
print $h->div ({ style=>"max-width:850px;" }, $h->ul ([$h->li (map { "$_: $policy->{$_}" } keys %{$policy})]));
-
 
150
 
-
 
151
print map { $h->div ({ class => "lisp0" }, [ 
-
 
152
    $h->div ({ class=>"liRight", style=>"margin-right:.5em" }, ucfirst ($_).": "),
-
 
153
    $h->div ({ class=>"liLeft" }, $policy->{$_} )]) } qw/ name type fee /;
-
 
154
 
-
 
155
 
80
print $h->div ({ class=>"error" }, "&nbsp;", "ERROR: You must agree to each term to continue.") if $terms and $terms < 8;
156
 
81
 
157
if ($policy->{type} eq "personal") {
82
print $h->h2 ("Release and Waiver of Liability");
158
  print $h->h2 ("Release and Waiver of Liability");
83
 
159
  
84
print $h->div ({ style=>"max-width:850px;" }, "RELEASE AND WAIVER OF LIABILITY, ASSUMPTION OF RISK, AND INDEMNITY AGREEMENT (\"Agreement\") IN CONSIDERATION of being permitted to participate this date, in any way, at any time, in Women’s Flat Track Roller Derby (\"Activity\"), I, for myself, my personal representatives, assigns, heirs, and next of kin:");
160
  print $h->div ({ style=>"max-width:850px;" }, "RELEASE AND WAIVER OF LIABILITY, ASSUMPTION OF RISK, AND INDEMNITY AGREEMENT (\"Agreement\") IN CONSIDERATION of being permitted to participate this date, in any way, at any time, in Women’s Flat Track Roller Derby (\"Activity\"), I, for myself, my personal representatives, assigns, heirs, and next of kin:");
-
 
161
  
-
 
162
  print $h->ol ({ style=>"max-width:850px;" }, [
-
 
163
    $h->li ("ACKNOWLEDGE, agree, and represent that I understand the nature of this Activity, and that I am qualified, in good health, and in proper physical condition to participate in such Activity. I further agree and warrant that if, at any time, I believe the conditions to be unsafe, I will immediately discontinue further participation in this Activity."),
-
 
164
    $h->li ("FULLY UNDERSTAND that: (a) THIS ACTIVITY INVOLVES RISKS AND DANGERS OF SERIOUS BODILY INJURY, INCLUDING PERMANENT DISABILITY, PARALYSIS, AND DEATH (\"Risks\"); (b) these Risks and dangers may be caused by my own actions or inactions, the actions or inactions of others participating in the Activity, the conditions in which the Activity takes place, or THE NEGLIGENCE OF THE \"RELEASEES\" NAMED BELOW; (c) there may be OTHER RISKS or SOCIAL AND ECONOMIC LOSSES either not known to me or not readily foreseeable at this time; and I FULLY ACCEPT AND ASSUME ALL SUCH RISKS AND ALL RESPONSIBILITY FOR LOSSES, COSTS, AND DAMAGES I incur as a result of my participation, in the Activity."),
-
 
165
    $h->li ("HEREBY RELEASE, DISCHARGE, AND COVENANT NOT TO SUE the sanctioning organization(s), their administrators, directors, agents, officers, members, volunteers, and employees, other participants, officials, rescue personnel, sponsors, advertisers, owners and lessees of Premises on which the Activity is conducted, (each of the forgoing shall be considered one of the RELEASEES herein) FROM ALL LIABILITY, CLAIMS, DEMANDS, LOSSES, OR DAMAGES ON MY ACCOUNT CAUSED, OR ALLEGED TO BE CAUSED, IN WHOLE OR IN PART BY THE NEGLIGENCE OF THE RELEASEES OR OTHERWISE, INCLUDING NEGLIGENT RESCUE OPERATIONS; AND I FURTHER AGREE that if, despite this RELEASE AND WAIVER OF LIABILITY, ASSUMPTION OF RISK, AND INDEMNITY AGREEMENT I, or anyone on my behalf, makes a claim against any of the RELEASEES, I WILL INDEMNIFY, SAVE, AND HOLD HARMLESS EACH OF THE RELEASEES from any litigation expenses, attorney fees, loss, liability, damage, or cost which may be incurred as the result of such claim."),
-
 
166
    ]);
-
 
167
  
-
 
168
  print $h->div ({ style=>"max-width:850px;" }, "I ACKNOWLEDGE THAT I AM OVER THE AGE OF 18 YEARS, HAVE READ THIS AGREEMENT AND FULLY UNDERSTAND ITS TERMS, UNDERSTAND THAT I HAVE GIVEN UP SUBSTANTIAL RIGHTS BY SIGNING IT, HAVE SIGNED IT FREELY AND WITHOUT ANY INDUCEMENT OR ASSURANCE OF ANY NATURE, AND I INTEND IT TO BE A COMPLETE AND UNCONDITIONAL RELEASE OF ALL LIABILITY TO THE GREATEST EXTENT ALLOWED BY LAW AND AGREE THAT IF ANY PORTION OF THIS AGREEMENT IS HELD TO BE INVALID, THE BALANCE, NOTWITHSTANDING, SHALL CONTINUE IN FULL FORCE AND EFFECT.");
Line 85... Line -...
85
 
-
 
86
print $h->ol ({ style=>"max-width:850px;" }, [
-
 
87
  $h->li ("ACKNOWLEDGE, agree, and represent that I understand the nature of this Activity, and that I am qualified, in good health, and in proper physical condition to participate in such Activity. I further agree and warrant that if, at any time, I believe the conditions to be unsafe, I will immediately discontinue further participation in this Activity."),
169
  print $h->br;
-
 
170
}
-
 
171
my $t = 1;
88
  $h->li ("FULLY UNDERSTAND that: (a) THIS ACTIVITY INVOLVES RISKS AND DANGERS OF SERIOUS BODILY INJURY, INCLUDING PERMANENT DISABILITY, PARALYSIS, AND DEATH (\"Risks\"); (b) these Risks and dangers may be caused by my own actions or inactions, the actions or inactions of others participating in the Activity, the conditions in which the Activity takes place, or THE NEGLIGENCE OF THE \"RELEASEES\" NAMED BELOW; (c) there may be OTHER RISKS or SOCIAL AND ECONOMIC LOSSES either not known to me or not readily foreseeable at this time; and I FULLY ACCEPT AND ASSUME ALL SUCH RISKS AND ALL RESPONSIBILITY FOR LOSSES, COSTS, AND DAMAGES I incur as a result of my participation, in the Activity."),
172
my @terms = map { $h->div ({ class => "lisp0", style=>"margin-bottom:1em" }, [
89
  $h->li ("HEREBY RELEASE, DISCHARGE, AND COVENANT NOT TO SUE the sanctioning organization(s), their administrators, directors, agents, officers, members, volunteers, and employees, other participants, officials, rescue personnel, sponsors, advertisers, owners and lessees of Premises on which the Activity is conducted, (each of the forgoing shall be considered one of the RELEASEES herein) FROM ALL LIABILITY, CLAIMS, DEMANDS, LOSSES, OR DAMAGES ON MY ACCOUNT CAUSED, OR ALLEGED TO BE CAUSED, IN WHOLE OR IN PART BY THE NEGLIGENCE OF THE RELEASEES OR OTHERWISE, INCLUDING NEGLIGENT RESCUE OPERATIONS; AND I FURTHER AGREE that if, despite this RELEASE AND WAIVER OF LIABILITY, ASSUMPTION OF RISK, AND INDEMNITY AGREEMENT I, or anyone on my behalf, makes a claim against any of the RELEASEES, I WILL INDEMNIFY, SAVE, AND HOLD HARMLESS EACH OF THE RELEASEES from any litigation expenses, attorney fees, loss, liability, damage, or cost which may be incurred as the result of such claim."),
173
    $h->div ({ class=>"liLeft" }, $_),
90
  ]);
174
    $h->div ({ class=>"liRight", onClick=>"document.forms['Attestation'].elements['Term$t'].click();" }, ["I Agree. ", $h->input ({ type => "checkbox", class => "attest", name => "Term".$t++, onClick=>"event.stopPropagation();" })])]) } @terms;
91
 
175
 
92
print $h->div ({ style=>"max-width:850px;" }, "I ACKNOWLEDGE THAT I AM OVER THE AGE OF 18 YEARS, HAVE READ THIS AGREEMENT AND FULLY UNDERSTAND ITS TERMS, UNDERSTAND THAT I HAVE GIVEN UP SUBSTANTIAL RIGHTS BY SIGNING IT, HAVE SIGNED IT FREELY AND WITHOUT ANY INDUCEMENT OR ASSURANCE OF ANY NATURE, AND I INTEND IT TO BE A COMPLETE AND UNCONDITIONAL RELEASE OF ALL LIABILITY TO THE GREATEST EXTENT ALLOWED BY LAW AND AGREE THAT IF ANY PORTION OF THIS AGREEMENT IS HELD TO BE INVALID, THE BALANCE, NOTWITHSTANDING, SHALL CONTINUE IN FULL FORCE AND EFFECT.");
176
print $h->div ({ style=>"max-width:850px;" }, [
93
print $h->br;
177
  $h->h3 ($policy->{name}),
94
print $h->div ({ style=>"max-width:850px;" }, [
178
  @terms,
95
  $h->div ({ class => "lisp0"}, [
179
#  $h->div ({ class => "lisp0"}, [
96
    $h->div ({ class=>"liLeft" }, "I have read and agree with the WFTDA Release and Waiver of Liability, Assumption of Risk, and Indemnity Agreement *Click here to download the Release and Waiver of Liability form."),
180
#    $h->div ({ class=>"liLeft" }, "I have read and agree with the WFTDA Release and Waiver of Liability, Assumption of Risk, and Indemnity Agreement *Click here to download the Release and Waiver of Liability form."),
97
    $h->div ({ class=>"liRight" }, ["I Agree. ", $h->input ({ type => "checkbox", class => "attest", name => "Term1" })])]),
181
#    $h->div ({ class=>"liRight" }, ["I Agree. ", $h->input ({ type => "checkbox", class => "attest", name => "Term1" })])]),
98
  $h->h3 ("Accidental Medical"),
182
#  $h->h3 ("Accidental Medical"),
99
  $h->div ({ class => "lisp0", style=>"margin-bottom:1em"}, [
183
#  $h->div ({ class => "lisp0", style=>"margin-bottom:1em"}, [
100
    $h->div ({ class=>"liLeft" }, "I am 18 or older."),
184
#    $h->div ({ class=>"liLeft" }, "I am 18 or older."),
101
    $h->div ({ class=>"liRight" }, ["I Agree. ", $h->input ({ type => "checkbox", class => "attest", name => "Term2" })])]),
185
#    $h->div ({ class=>"liRight" }, ["I Agree. ", $h->input ({ type => "checkbox", class => "attest", name => "Term2" })])]),
102
  $h->div ({ class => "lisp0", style=>"margin-bottom:1em"}, [
186
#  $h->div ({ class => "lisp0", style=>"margin-bottom:1em"}, [
103
    $h->div ({ class=>"liLeft" }, "I am obtaining coverage for myself (I may not acquire coverage on behalf of someone else)."),
187
#    $h->div ({ class=>"liLeft" }, "I am obtaining coverage for myself (I may not acquire coverage on behalf of someone else)."),
-
 
188
#    $h->div ({ class=>"liRight" }, ["I Agree. ", $h->input ({ type => "checkbox", class => "attest", name => "Term3" })])]),
-
 
189
#  $h->div ({ class => "lisp0", style=>"margin-bottom:1em"}, [
-
 
190
#    $h->div ({ class=>"liLeft" }, "My league has WFTDA Insurance. I understand I must obtain the same coverage as my league. If I am not affiliated with a league, I understand coverage is only valid when I skate with a WFTDA insured league."),
-
 
191
#    $h->div ({ class=>"liRight" }, ["I Agree. ", $h->input ({ type => "checkbox", class => "attest", name => "Term4" })])]),
-
 
192
#  $h->div ({ class => "lisp0", style=>"margin-bottom:1em"}, [
-
 
193
#    $h->div ({ class=>"liLeft" }, "I understand in order for insurance coverage to be in effect, I must adhere to the applicable Risk Management Guidelines and/or rules for the activity in which I am participating. Failure to do so will result in denial of claims and may result in revocation of coverage."),
-
 
194
#    $h->div ({ class=>"liRight" }, ["I Agree. ", $h->input ({ type => "checkbox", class => "attest", name => "Term5" })])]),
-
 
195
#  $h->div ({ class => "lisp0", style=>"margin-bottom:1em"}, [
-
 
196
#    $h->div ({ class=>"liLeft" }, "I understand if I am injured, I am responsible to submit an injury report, and must do so within 14 days of the date of my injury. I can request injury reports from insurance\@wftda.com. My league may assist me with this, but ultimately, it is my responsibility. Failure to submit an injury report within the allowable grace period will result in the denial of my claim."),
104
    $h->div ({ class=>"liRight" }, ["I Agree. ", $h->input ({ type => "checkbox", class => "attest", name => "Term3" })])]),
197
#    $h->div ({ class=>"liRight" }, ["I Agree. ", $h->input ({ type => "checkbox", class => "attest", name => "Term6" })])]),
105
  $h->div ({ class => "lisp0", style=>"margin-bottom:1em"}, [
-
 
106
    $h->div ({ class=>"liLeft" }, "My league has WFTDA Insurance. I understand I must obtain the same coverage as my league. If I am not affiliated with a league, I understand coverage is only valid when I skate with a WFTDA insured league."),
-
 
107
    $h->div ({ class=>"liRight" }, ["I Agree. ", $h->input ({ type => "checkbox", class => "attest", name => "Term4" })])]),
-
 
108
  $h->div ({ class => "lisp0", style=>"margin-bottom:1em"}, [
-
 
109
    $h->div ({ class=>"liLeft" }, "I understand in order for insurance coverage to be in effect, I must adhere to the applicable Risk Management Guidelines and/or rules for the activity in which I am participating. Failure to do so will result in denial of claims and may result in revocation of coverage."),
-
 
110
    $h->div ({ class=>"liRight" }, ["I Agree. ", $h->input ({ type => "checkbox", class => "attest", name => "Term5" })])]),
-
 
111
  $h->div ({ class => "lisp0", style=>"margin-bottom:1em"}, [
-
 
112
    $h->div ({ class=>"liLeft" }, "I understand if I am injured, I am responsible to submit an injury report, and must do so within 14 days of the date of my injury. I can request injury reports from insurance\@wftda.com. My league may assist me with this, but ultimately, it is my responsibility. Failure to submit an injury report within the allowable grace period will result in the denial of my claim."),
-
 
113
    $h->div ({ class=>"liRight" }, ["I Agree. ", $h->input ({ type => "checkbox", class => "attest", name => "Term6" })])]),
-
 
114
  $h->div ({ class => "lisp0", style=>"margin-bottom:1em"}, [
198
#  $h->div ({ class => "lisp0", style=>"margin-bottom:1em"}, [
115
    $h->div ({ class=>"liLeft" }, "I understand coverage is non-refundable and non-transferable. Coverage only transfers to other WFTDA Insured leagues."),
199
#    $h->div ({ class=>"liLeft" }, "I understand coverage is non-refundable and non-transferable. Coverage only transfers to other WFTDA Insured leagues."),
Line 116... Line 200...
116
    $h->div ({ class=>"liRight" }, ["I Agree. ", $h->input ({ type => "checkbox", class => "attest", name => "Term7" })])]),
200
#    $h->div ({ class=>"liRight" }, ["I Agree. ", $h->input ({ type => "checkbox", class => "attest", name => "Term7" })])]),
Line 117... Line 201...
117
  $h->div ({ class => "lisp0", style=>"margin-bottom:1em"}, [
201
#  $h->div ({ class => "lisp0", style=>"margin-bottom:1em"}, [
Line 159... Line 243...
159
 
243
 
160
 
244
 
161
 
245
 
-
 
246
sub sendToSquare {
162
sub sendToSquare {
247
  my $esig = shift || return "ERROR: No Signature";
Line 163... Line 248...
163
  my $esig = shift || return "ERROR: No Signature";
248
  my $terms = shift // return "ERROR: No Term Count";
164
  my $terms = shift // 8;
249
  my $policy = shift // return "ERROR: No Policy ID";
165
  my $user_tz = param ("timezone") // 'America/Chicago';
250
  my $user_tz = param ("timezone") // 'America/Chicago';
166
  
251
  
Line 167... Line 252...
167
  use REST::Client;
252
  use REST::Client;
168
  use JSON;
253
  use JSON;
Line 169... Line 254...
169
  use Data::Dumper;
254
  use Data::Dumper;
170
  use UUID::Tiny qw(create_UUID_as_string UUID_V4);
255
  use UUID::Tiny qw(create_UUID_as_string UUID_V4);
Line 171... Line 256...
171
  
256
  
Line 182... Line 267...
182
    };
267
    };
Line 183... Line 268...
183
  
268
  
184
  my $body = {
269
  my $body = {
185
    "idempotency_key" => "$uuid_v4_string",
270
    "idempotency_key" => "$uuid_v4_string",
186
    "checkout_options" => {
271
    "checkout_options" => {
187
      "redirect_url"  => url ( -base => 1)."/confirmation",
272
      "redirect_url"  => url ( -base => 1 )."/confirmation",
188
      "enable_coupon" => JSON::false
273
      "enable_coupon" => JSON::false
189
    },
274
    },
190
#    "quick_pay" => {
275
#    "quick_pay" => {
191
#      "name" => $policy->{name},
276
#      "name" => $policy->{name},
Line 201... Line 286...
201
      "discounts"   => isWFTDAMember ($user->{id}) ? [{
286
      "discounts"   => isWFTDAMember ($user->{id}) ? [{
202
        "name"  => "WFTDA Member Discount",
287
        "name"  => "WFTDA Member Discount",
203
        "scope" => "ORDER",
288
        "scope" => "ORDER",
204
#        "type" => "FIXED_AMOUNT",
289
#        "type" => "FIXED_AMOUNT",
205
        "amount_money" => {
290
        "amount_money" => {
206
          "amount"   => getSetting ("WFTDA_MEMBER_DISCOUNT") * 100,
291
#          "amount"   => getSetting ("WFTDA_MEMBER_DISCOUNT") * 100,
-
 
292
          "amount"   => $policy->{member_discount} * 100,
207
          "currency" => "USD"
293
          "currency" => "USD"
208
        }
294
        }
209
      }] : [],
295
      }] : [],
210
      "line_items" => [{
296
      "line_items" => [{
211
        "name" => $policy->{name},
297
        "name" => $policy->{name},
Line 224... Line 310...
224
    '/v2/online-checkout/payment-links', 
310
    '/v2/online-checkout/payment-links', 
225
    $json_body,
311
    $json_body,
226
    $headers
312
    $headers
227
  );
313
  );
228
  my $response = from_json($client->responseContent());
314
  my $response = from_json($client->responseContent());
-
 
315
  
-
 
316
  warn '/v2/online-checkout/payment-links/'.$response->{payment_link}->{id};
-
 
317
  $body->{payment_link}->{checkout_options}->{redirect_url} = url ( -base => 1 )."/confirmation?order_id=".$response->{payment_link}->{order_id};
-
 
318
  $body->{payment_link}->{version} = $response->{payment_link}->{version};
-
 
319
  $json_body = encode_json $body;
-
 
320
  $client->PUT(
-
 
321
    '/v2/online-checkout/payment-links/'.$response->{payment_link}->{id},
-
 
322
    $json_body,
-
 
323
    $headers
-
 
324
  );
-
 
325
  my $response2 = from_json($client->responseContent());
-
 
326
  
-
 
327
  
229
#  warn Dumper($response);
328
  warn Dumper($response2);
Line 230... Line 329...
230
  
329
  
Line 231... Line 330...
231
#  warn $response->{payment_link}->{url};
330
#  warn $response->{payment_link}->{url};
232
  
331
  
Line 233... Line 332...
233
  $response->{payment_link}->{created_at} =~ s/T/ /;
332
  $response->{payment_link}->{created_at} =~ s/T/ /;
234
  $response->{payment_link}->{created_at} =~ s/Z$//;
333
  $response->{payment_link}->{created_at} =~ s/Z$//;
235
  
334
  
236
  $dbh->do ("insert into square_order
335
  $dbh->do ("insert into square_order
237
             (square_id, order_id, person_id, url, idempotency_key, created, user_ip, amount, status, attestation)
336
             (square_id, order_id, person_id, organization_id, policy_id, url, idempotency_key, created, user_ip, amount, status, attestation)
238
             values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", undef,
337
             values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", undef,
-
 
338
             $response->{payment_link}->{id},
-
 
339
             $response->{payment_link}->{order_id},
239
             $response->{payment_link}->{id},
340
             $user->{id},
240
             $response->{payment_link}->{order_id},
341
             $league_id,
241
             $user->{id},
342
             $policy->{id},
242
             $response->{payment_link}->{url},
343
             $response->{payment_link}->{url},
243
             $uuid_v4_string,
344
             $uuid_v4_string,
Line 252... Line 353...
252
  logit ($user->{id}, "Redirected to Square for payment");
353
  logit ($user->{id}, "Redirected to Square for payment");
253
  print $cgi->redirect ($response->{payment_link}->{url});
354
  print $cgi->redirect ($response->{payment_link}->{url});
Line 254... Line 355...
254
  
355
  
255
  exit;
356
  exit;
-
 
357
}
-
 
358
 
-
 
359
sub ERROR {
-
 
360
  my $header = shift // "Unknown Error";
-
 
361
  my $text   = shift // "Something unexpectedly bad happened.";
-
 
362
  my $logmsg = shift // "Unknown Error happened while viewing the Attestation page";
-
 
363
  
-
 
364
  print header (-cookie=>CGI::Cookie->new(-name=>'PEEPSAUTH',-value=>"$cookie_string"));
-
 
365
  printRCHeader("Atttestation");
-
 
366
  print $h->close ("table");
-
 
367
  print $h->h2 ($header);
-
 
368
  print $h->div ({ style=>"max-width:450px;" }, $text, "&nbsp;");
-
 
369
  print $h->button ({onclick => "window.location.href='/';"}, "Home");
-
 
370
  print $h->close ("BODY", "HTML");
-
 
371
  logit ($user->{id}, $logmsg);
-
 
372
  exit; 
256
}
373
}