-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathCheckout.aspx.vb
More file actions
2227 lines (1915 loc) · 122 KB
/
Checkout.aspx.vb
File metadata and controls
2227 lines (1915 loc) · 122 KB
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'========================================================================
'Kartris - www.kartris.com
'Copyright 2024 CACTUSOFT
'GNU GENERAL PUBLIC LICENSE v2
'This program is free software distributed under the GPL without any
'warranty.
'www.gnu.org/licenses/gpl-2.0.html
'KARTRIS COMMERCIAL LICENSE
'If a valid license.config issued by Cactusoft is present, the KCL
'overrides the GPL v2.
'www.kartris.com/t-Kartris-Commercial-License.aspx
'========================================================================
Imports System.Data
Imports System.Data.Common
Imports System.Data.SqlClient
Imports System.Web.Configuration
Imports KartSettingsManager
Imports CkartrisBLL
Imports CkartrisDataManipulation
Imports MailChimp.Net.Models
Imports System.Threading.Tasks
''' <summary>
''' Checkout - this page handles users checking out,
''' the subsequent confirmation page, and then
''' formats the form which is posted to payment
''' gateways to initiate a payment.
''' </summary>
Partial Class _Checkout
Inherits PageBaseClass
Private _SelectedPaymentMethod As String = ""
Private _blnAnonymousCheckout As Boolean = False
''' <summary>
''' Page Load
''' </summary>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
'---------------------------------------
'SET PAGE TITLE
'---------------------------------------
Page.Title = GetLocalResourceObject("PageTitle_CheckOut") & " | " & Server.HtmlEncode(GetGlobalResourceObject("Kartris", "Config_Webshopname"))
'---------------------------------------
'GET LIST OF PAYMENT GATEWAYS
'This comes from a config setting that
'is populated dynamically from the
'available payment gateways that are
'turned on in the 'plugins' folder.
'---------------------------------------
Dim strPaymentMethods As String = GetKartConfig("frontend.payment.gatewayslist")
'---------------------------------------
'CHECK IF USER IS LOGGED IN
'---------------------------------------
Dim blnAuthorized As Boolean = False
If CurrentLoggedUser IsNot Nothing Then
blnAuthorized = CurrentLoggedUser.isAuthorized
End If
'---------------------------------------
'SHOW CUSTOMER COMMENTS BOX?
'---------------------------------------
If GetKartConfig("frontend.checkout.comments.enabled") = "n" Then
phdCustomerComments.Visible = False
End If
'=======================================
'PAYMENT GATEWAYS
'Paypal, SagePay, etc.
'=======================================
Dim arrPaymentsMethods As String() = Split(strPaymentMethods, ",")
'If the order value inclusive of everything is zero, we don't want
'to bill the customer. Instead we activate the PO method, even if
'this user is not authorized to use it. We hide the other payment
'methods.
Dim objBasket As Kartris.Basket = Session("Basket")
Dim blnOrderIsFree As Boolean = False 'Disable, suspect this might misfire (objBasket.FinalPriceIncTax = 0)
'This line below looks a bit more complicated than it should. We have seen
'some cases where orders slip by without payment, when they should not. It doesn't seem
'to be possible, but apparently has happened in some cases. The code below is an idea to try
'to stop this, the assumption that if the finalprice shows as zero because of some glitch,
'maybe the first item in the basket would have a zero name too. Or that maybe it will trigger
'an error. Only time will tell. If this causes problems, comment it out and just stop accepting
'free orders (most sites don't do this, but some use it to give promotions away).
Try
blnOrderIsFree = (objBasket.FinalPriceIncTax = 0 And objBasket.BasketItems.Item(0).Name <> "")
Catch ex As Exception
'order stays as not free
End Try
If blnOrderIsFree Then
'Add the PO option with name 'FREE' and hide payment selection
'The 'False' flag indicates this is not for authorized users
'only. PO normally is, but here we are using this for all users
'if total price is zero.
ddlPaymentGateways.Items.Add(New ListItem("FREE", "po_offlinepayment" & "::False"))
updPaymentMethods.Visible = False
valPaymentGateways.Enabled = False
Else
'Order isn't free. Load up the payment gateways.
Try
'Add the default 'Please select' line at top of menu
ddlPaymentGateways.Items.Add(New ListItem(GetGlobalResourceObject("Kartris", "ContentText_DropdownSelectDefault"), "::False"))
'---------------------------------------
'LOOP THROUGH PAYMENT METHODS
'---------------------------------------
For Each strGatewayEntry As String In arrPaymentsMethods
'The config setting stores info for each gateway,
'separated by double colons (::)
Dim arrGateway As String() = Split(strGatewayEntry, "::")
'---------------------------------------
'CHECK PAYMENT GATEWAY DATA VALID
'We shoud have 5 bits of data (in a zero
'based array).
'---------------------------------------
If UBound(arrGateway) = 4 Then
Dim blnOkToAdd As Boolean = True
'Is this a payment gateway? (value='p')
If arrGateway(4) = "p" Then
'Is this only available for 'authorized'
'customers? For offline (PO) orders in
'particular, you probably only want
'trusted customers to be able to use it.
'To do this, set the gateway's settings
'to 'Authorized Only' and then edit any
'customer you want to be able to use this
'payment system to 'Authorize' them.
If LCase(arrGateway(2)) = "true" Then
blnOkToAdd = blnAuthorized
End If
'---------------------------------------
'CHECK STATUS OF GATEWAY
'There are four possibilities
'On, Off, Test, Fake
'The last two are for use when testing
'a payment system. 'Test' will pass an
'order through using the gateways test
'mode, if available. 'Fake' bypasses
'the payment gateway completely, and
'just simulates the callback the gateway
'should make to your callback page.
'For more info, see the PDF User Guide.
'Test/Fake are only available if you are
'logged in as a back end admin. This
'means you can setup and test a new
'payment system on a live site without
'it being visible to customers.
'---------------------------------------
If LCase(arrGateway(1)) = "test" Or LCase(arrGateway(1)) = "fake" Then
blnOkToAdd = HttpSecureCookie.IsBackendAuthenticated
'Gateway is turned off, don't add it
'to the list.
ElseIf LCase(arrGateway(1)) = "off" Then
blnOkToAdd = False
End If
Else
'Not a payment system... shipping plugins for
'USPS, UPS, etc. are stored in the same
'plugins folder, but we don't want them
'available as a choice of payment system!
blnOkToAdd = False
End If
'This is a payment system and is available to
'this customer
If blnOkToAdd Then
Dim strGatewayName As String = arrGateway(0)
'Get the 'friendly' name of the payment system from
'the gateway's config. Note you can have friendly
'names for multiple languages in the config file:
'<setting name="FriendlyName(en-GB)" serializeAs="String">
'<value>Offline payment</value>
'</setting>
Dim strFriendlyName As String = Payment.GetPluginFriendlyName(strGatewayName)
'If no friendly name, use the Gateway's default name
'(Paypal, SagePay, etc.)
'Friendly name is better, because 'SagePay' probably means
'less to a customer than 'Pay with Credit Card'
If Interfaces.Utils.TrimWhiteSpace(strFriendlyName) <> "" Then
ddlPaymentGateways.Items.Add(New ListItem(strFriendlyName, arrGateway(0).ToString & "::" & arrGateway(3).ToString))
Else
ddlPaymentGateways.Items.Add(New ListItem(strGatewayName, arrGateway(0).ToString & "::" & arrGateway(3).ToString))
End If
If strGatewayName.ToLower = "po_offlinepayment" Then
'Default name for PO (offline payment)
strGatewayName = GetGlobalResourceObject("Checkout", "ContentText_Po")
End If
End If
Else
'Didn't have the four values needed for payment
'gateway config
Throw New Exception("Invalid gatewaylist config setting!")
End If
Next
'---------------------------------------
'SHOW PAYMENT METHODS DROPDOWN
'Note that the count of gateways we get
'from the dropdown menu, but that has
'an extra line 'Please select', so the
'count will be 1 higher than the actual
'number of gateways. Hence '1' means no
'payment systems, '2' means there is one
'and so on.
'---------------------------------------
'If there are no valid payment systems (Count = 1),
'we log an exception.
If ddlPaymentGateways.Items.Count = 1 Then
Throw New Exception("No valid payment gateways")
'If there is one (Count = 2) then we don't need to
'show the user a choice, since there is
'only one to choose from. So we default to
'that and hide the validators and dropdown.
ElseIf ddlPaymentGateways.Items.Count = 2 Then
Dim arrSelectedGateway() As String = Split(ddlPaymentGateways.Items(1).Value, "::")
_SelectedPaymentMethod = arrSelectedGateway(0)
_blnAnonymousCheckout = CBool(arrSelectedGateway(1))
ddlPaymentGateways.SelectedValue = ddlPaymentGateways.Items(1).Value
phdPaymentMethods.Visible = False
valPaymentGateways.Enabled = False 'disable validation just to be sure
If _SelectedPaymentMethod = "PO_OfflinePayment" Then phdPONumber.Visible = True Else phdPONumber.Visible = False
'Store value in hidden field. We hope this will be more
'robust if page times out
litPaymentGatewayHidden.Text = _SelectedPaymentMethod
Else
'More than one payment method available,
'show dropdown and give user the choice.
'Hide the PO number field.
phdPaymentMethods.Visible = True
'txtPurchaseOrderNo.Style.Item("display") = "none"
'phdPONumber.Style.Item("display") = "none"
phdPONumber.Visible = False
End If
'---------------------------------------
'ERROR LOADING PAYMENT GATEWAYS LIST
'---------------------------------------
Catch ex As Exception
Throw New Exception("Error loading payment gateway list")
End Try
End If
'---------------------------------------
'CLEAR ADDRESS CONTROLS
'---------------------------------------
UC_BillingAddress.Clear()
UC_ShippingAddress.Clear()
'---------------------------------------
'CUSTOMER OPTION TO SELECT
'EMAIL UPDATES OF ORDER STATUS?
'---------------------------------------
If GetKartConfig("frontend.checkout.ordertracking") <> "n" And GetKartConfig("backend.orders.emailupdates") <> "n" Then
phdOrderEmails.Visible = True
Else
phdOrderEmails.Visible = False
chkOrderEmails.Checked = False
End If
'---------------------------------------
'SHOW MAILING LIST OPT-IN BOX?
'---------------------------------------
If GetKartConfig("frontend.users.mailinglist.enabled") <> "n" Then
phdMailingList.Visible = True
chkMailingList.Checked = False
Else
phdMailingList.Visible = False
chkMailingList.Checked = False
End If
'---------------------------------------
'SHOW SAVE-BASKET OPTION?
'Customers can save the basket if they
'want to make the same order again in
'future
'---------------------------------------
If GetKartConfig("frontend.checkout.savebasket") <> "n" Then phdSaveBasket.Visible = True Else phdSaveBasket.Visible = False
'---------------------------------------
'SHOW Ts & Cs CHECKBOX CONFIRMATION?
'---------------------------------------
If GetKartConfig("frontend.checkout.termsandconditions") <> "n" Then phdTermsAndConditions.Visible = True Else phdTermsAndConditions.Visible = False
ConfigureAddressFields()
Else
End If
'=======================================
'SHOW LOGIN BOX
'If the user is not logged in, or has
'not proceeded through first steps of
'creating new user, then we show the
'login / new user options.
'The 'proceed' button is hidden.
'=======================================
If Not (UC_KartrisLogin.Cleared Or User.Identity.IsAuthenticated) Then
'Show login box
mvwCheckout.ActiveViewIndex = 0
btnProceed.Visible = False
Else
'Show checkout form if not already set to
'go to confirmation page
If mvwCheckout.ActiveViewIndex <> 2 Then mvwCheckout.ActiveViewIndex = 1 Else valSummary.Enabled = False
btnProceed.Visible = True
End If
'=======================================
'SETUP CHECKOUT FORM
'Runs if user is logged in already
'=======================================
If Not IsNothing(CurrentLoggedUser) Then
'Show checkout form if not already set to
'go to confirmation page
If mvwCheckout.ActiveViewIndex <> 2 Then mvwCheckout.ActiveViewIndex = 1 Else valSummary.Enabled = False
'Fresh form arrival
If Not Page.IsPostBack Then
'Set up first user address (billing)
Dim lstUsrAddresses As Collections.Generic.List(Of KartrisClasses.Address) = Nothing
'---------------------------------------
'BILLING ADDRESS
'---------------------------------------
If UC_BillingAddress.Addresses Is Nothing Then
'Find all addresses in this user's account
lstUsrAddresses = KartrisClasses.Address.GetAll(CurrentLoggedUser.ID)
'Populate dropdown by filtering billing/universal addresses
UC_BillingAddress.Addresses = lstUsrAddresses.FindAll(Function(p) p.Type = "b" Or p.Type = "u")
End If
'---------------------------------------
'SHIPPING ADDRESS
'---------------------------------------
If UC_ShippingAddress.Addresses Is Nothing Then
'Find all addresses in this user's account
If lstUsrAddresses Is Nothing Then lstUsrAddresses = KartrisClasses.Address.GetAll(CurrentLoggedUser.ID)
'Populate dropdown by filtering shipping/universal addresses
UC_ShippingAddress.Addresses = lstUsrAddresses.FindAll(Function(ShippingAdd) ShippingAdd.Type = "s" Or ShippingAdd.Type = "u")
End If
'---------------------------------------
'SHIPPING/BILLING ADDRESS NOT SAME
'---------------------------------------
If (Not CurrentLoggedUser.DefaultBillingAddressID = CurrentLoggedUser.DefaultShippingAddressID) Then
If Not _blnAnonymousCheckout Then
chkSameShippingAsBilling.Checked = False
Else
chkSameShippingAsBilling.Checked = True
End If
Else
chkSameShippingAsBilling.Checked = True
End If
If UC_BasketSummary.GetBasket.AllDigital Then
pnlShippingAddress.Visible = False
UC_ShippingAddress.Visible = False
Else
If Not chkSameShippingAsBilling.Checked Then
'Show shipping address block
pnlShippingAddress.Visible = True
UC_ShippingAddress.Visible = True
Else
pnlShippingAddress.Visible = False
UC_ShippingAddress.Visible = False
End If
End If
'---------------------------------------
'SELECT DEFAULT ADDRESSES
'---------------------------------------
If UC_BillingAddress.SelectedID = 0 Then
UC_BillingAddress.SelectedID = CurrentLoggedUser.DefaultBillingAddressID
End If
If UC_ShippingAddress.SelectedID = 0 Then
UC_ShippingAddress.SelectedID = CurrentLoggedUser.DefaultShippingAddressID
End If
End If
End If
End Sub
''' <summary>
''' Page Load Complete
''' </summary>
Protected Sub Page_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadComplete
'Fails for new users
If Not Me.IsPostBack Then
Try
Dim objUsersBLL As New UsersBLL
If txtEUVAT.Text = "" And phdEUVAT.Visible = True Then
txtEUVAT.Text = objUsersBLL.GetCustomerEUVATNumber(CurrentLoggedUser.ID)
End If
Catch ex As Exception
'probably a new user or don't need vate
End Try
End If
'---------------------------------------
'ZERO ITEMS IN BASKET!
'---------------------------------------
If UC_BasketView.GetBasketItems.Count = 0 Then Response.Redirect("~/Basket.aspx")
'---------------------------------------
'CHECK MINIMUM ORDER VALUE MET
'---------------------------------------
Dim numMinOrderValue As Double = CDbl(GetKartConfig("frontend.orders.minordervalue"))
If numMinOrderValue > 0 Then
If GetKartConfig("general.tax.pricesinctax") = "y" Then
'Prices include tax
If UC_BasketView.GetBasket.TotalIncTax < CurrenciesBLL.ConvertCurrency(Session("CUR_ID"), numMinOrderValue) Then
Response.Redirect("~/Basket.aspx?error=minimum")
End If
Else
If UC_BasketView.GetBasket.TotalExTax < CurrenciesBLL.ConvertCurrency(Session("CUR_ID"), numMinOrderValue) Then
Response.Redirect("~/Basket.aspx?error=minimum")
End If
End If
End If
'Just to be sure we get shipping price, have
'had issues where sometimes a single shipping method
'doesn't trigger lookup for shipping price
'UC_BasketView.RefreshShippingMethods()
'If Not Me.IsPostBack() Then
' txtEUVAT_AutoPostback()
'End If
End Sub
''' <summary>
''' Payment Method Changed, refresh
''' </summary>
Protected Sub ddlPaymentGateways_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlPaymentGateways.SelectedIndexChanged
Dim arrSelectedGateway() As String = Split(ddlPaymentGateways.SelectedItem.Value, "::")
_SelectedPaymentMethod = arrSelectedGateway(0)
_blnAnonymousCheckout = CBool(arrSelectedGateway(1))
ConfigureAddressFields(True)
'Store value in hidden field. We hope this will be more
'robust if page times out
litPaymentGatewayHidden.Text = _SelectedPaymentMethod
'Decide whether to show PO field
If _SelectedPaymentMethod = "PO_OfflinePayment" Then
phdPONumber.Visible = True
Else
phdPONumber.Visible = False
txtPurchaseOrderNo.Text = ""
litPONumberText.Text = ""
End If
End Sub
''' <summary>
''' Show or Hide Address Fields depending on the selected payment gateway and basket contents
''' </summary>
''' <remarks></remarks>
Private Sub ConfigureAddressFields(Optional ByVal blnUpdateAddressPanel As Boolean = False)
If _blnAnonymousCheckout Then
chkSameShippingAsBilling.Visible = False
chkSameShippingAsBilling.Checked = False
lblchkSameShipping.Visible = False
UC_BillingAddress.Visible = False
Else
chkSameShippingAsBilling.Visible = True
'chkSameShippingAsBilling.Checked = True
lblchkSameShipping.Visible = True
UC_BillingAddress.Visible = True
End If
If UC_BasketSummary.GetBasket.AllDigital Then
pnlShippingAddress.Visible = False
UC_ShippingAddress.Visible = False
chkSameShippingAsBilling.Visible = False
lblchkSameShipping.Visible = False
Else
If Not _blnAnonymousCheckout Then
chkSameShippingAsBilling.Visible = True
lblchkSameShipping.Visible = True
If chkSameShippingAsBilling.Checked Then
pnlShippingAddress.Visible = False
UC_ShippingAddress.Visible = False
Else
pnlShippingAddress.Visible = True
UC_ShippingAddress.Visible = True
End If
Else
pnlShippingAddress.Visible = True
UC_ShippingAddress.Visible = True
End If
End If
If blnUpdateAddressPanel Then updAddresses.Update()
End Sub
''' <summary>
''' Billing country changed, refresh
''' shipping methods
''' </summary>
Protected Sub BillingCountryUpdated(ByVal sender As Object, ByVal e As System.EventArgs) Handles UC_BillingAddress.CountryUpdated
If chkSameShippingAsBilling.Checked Then
pnlShippingAddress.Visible = False
UC_ShippingAddress.Visible = False
RefreshShippingMethods("billing")
Else
pnlShippingAddress.Visible = True
UC_ShippingAddress.Visible = True
RefreshShippingMethods("shipping")
End If
updAddresses.Update()
End Sub
''' <summary>
''' Shipping country updated, refresh
''' shipping methods
''' </summary>
Protected Sub ShippingCountryUpdated(ByVal sender As Object, ByVal e As System.EventArgs) Handles UC_ShippingAddress.CountryUpdated
If chkSameShippingAsBilling.Checked Then
pnlShippingAddress.Visible = False
UC_ShippingAddress.Visible = False
RefreshShippingMethods("billing")
Else
pnlShippingAddress.Visible = True
UC_ShippingAddress.Visible = True
RefreshShippingMethods("shipping")
End If
updAddresses.Update()
End Sub
''' <summary>
''' The checkbox for 'same shipping
''' as billing address' has been
''' changed (checked/unchecked))
''' </summary>
Protected Sub chkSameShippingAsBilling_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkSameShippingAsBilling.CheckedChanged
If chkSameShippingAsBilling.Checked Then
pnlShippingAddress.Visible = False
UC_ShippingAddress.Visible = False
RefreshShippingMethods("billing")
Else
pnlShippingAddress.Visible = True
UC_ShippingAddress.Visible = True
RefreshShippingMethods("shipping")
End If
updAddresses.Update()
End Sub
''' <summary>
''' Refresh shipping methods
''' </summary>
Private Sub RefreshShippingMethods(Optional ByVal strControl As String = "shipping")
Dim numShippingDestinationID As Integer
If strControl = "billing" Then
If UC_BillingAddress.SelectedAddress IsNot Nothing Then
numShippingDestinationID = UC_BillingAddress.SelectedAddress.CountryID
Else
numShippingDestinationID = 0
End If
Else
If UC_ShippingAddress.SelectedAddress IsNot Nothing Then
numShippingDestinationID = UC_ShippingAddress.SelectedAddress.CountryID
Else
numShippingDestinationID = 0
End If
End If
'=======================================
'EU VAT and EORI fields
'New brexit-related changes
'=======================================
Dim adrShipping As KartrisClasses.Address = Nothing
If chkSameShippingAsBilling.Checked Then
'Shipping address same as billing
'so use billing address (as shipping
'address)
If UC_BillingAddress.SelectedID > 0 Then
adrShipping = UC_BillingAddress.Addresses.Find(Function(Add) Add.ID = UC_BillingAddress.SelectedID)
ElseIf numShippingDestinationID > 0 Then
adrShipping = UC_BillingAddress.SelectedAddress
End If
Else
'Must use shipping address
If UC_ShippingAddress.SelectedID > 0 Then
adrShipping = UC_ShippingAddress.Addresses.Find(Function(Add) Add.ID = UC_ShippingAddress.SelectedID)
ElseIf numShippingDestinationID > 0 Then
adrShipping = UC_ShippingAddress.SelectedAddress
End If
End If
'Two new functions determine whether to show EU VAT and EORI fields at checkout
Try
phdEUVAT.Visible = CkartrisRegionalSettings.ShowEUVATField(UCase(GetKartConfig("general.tax.euvatcountry")), adrShipping.Country.IsoCode, adrShipping.Country.D_Tax, adrShipping.Country.TaxExtra, GetKartConfig("general.tax.domesticshowfield") = "y")
Catch ex As Exception
phdEUVAT.Visible = False
End Try
Try
phdEORI.Visible = CkartrisRegionalSettings.ShowEORIField(adrShipping.Country.D_Tax, adrShipping.Country.TaxExtra)
Catch ex As Exception
phdEORI.Visible = False
End Try
If phdEUVAT.Visible Then
'Show VAT country ISO code in front of field
litMSCode.Text = adrShipping.Country.IsoCode
'EU uses 'EL' for Greece, and not the
'ISO code 'GR', so we need to adjust for this
If litMSCode.Text = "GR" Then litMSCode.Text = "EL"
'Try to fill EU number
Try
Dim objUsersBLL As New UsersBLL
txtEUVAT.Text = objUsersBLL.GetCustomerEUVATNumber(CurrentLoggedUser.ID)
Catch ex As Exception
End Try
Else
'Country of user is same as store
'Hide VAT box
txtEUVAT.Text = ""
Call txtEUVAT_AutoPostback()
End If
If phdEORI.Visible Then
'Try to fill EU number
Dim objObjectConfigBLL As New ObjectConfigBLL
Try
txtEORI.Text = objObjectConfigBLL.GetValue("K:user.eori", CurrentLoggedUser.ID)
Catch ex As Exception
End Try
End If
'=======================================================
'SET SHIPPING DETAILS FROM ADDRESS CONTROL
'=======================================================
Dim objShippingDetails As New Interfaces.objShippingDetails
Try
With objShippingDetails.RecipientsAddress
If chkSameShippingAsBilling.Checked Then
.Postcode = UC_BillingAddress.SelectedAddress.Postcode
.CountryID = UC_BillingAddress.SelectedAddress.Country.CountryId
.CountryIsoCode = UC_BillingAddress.SelectedAddress.Country.IsoCode
.CountryName = UC_BillingAddress.SelectedAddress.Country.Name
Else
.Postcode = UC_ShippingAddress.SelectedAddress.Postcode
.CountryID = UC_ShippingAddress.SelectedAddress.Country.CountryId
.CountryIsoCode = UC_ShippingAddress.SelectedAddress.Country.IsoCode
.CountryName = UC_ShippingAddress.SelectedAddress.Country.Name
End If
End With
Catch ex As Exception
End Try
'=======================================
'UPDATE BASKET WITH SHIPPING DETAILS
'=======================================
UC_BasketView.ShippingDetails = objShippingDetails
UC_BasketSummary.ShippingDetails = objShippingDetails
UC_BasketView.ShippingDestinationID = numShippingDestinationID
UC_BasketSummary.ShippingDestinationID = numShippingDestinationID
UC_BasketView.RefreshShippingMethods()
End Sub
''' <summary>
''' Proceed button clicked, moves us
''' to next stage
''' </summary>
Protected Sub btnProceed_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnProceed.Click
If String.IsNullOrEmpty(_SelectedPaymentMethod) Then
Dim arrSelectedGateway() As String = Split(ddlPaymentGateways.SelectedItem.Value, "::")
_SelectedPaymentMethod = arrSelectedGateway(0)
_blnAnonymousCheckout = CBool(arrSelectedGateway(1))
End If
Dim clsPlugin As Kartris.Interfaces.PaymentGateway = Nothing
Dim strGatewayName As String = _SelectedPaymentMethod
If mvwCheckout.ActiveViewIndex > "0" Then
clsPlugin = Payment.PPLoader(strGatewayName)
If LCase(clsPlugin.Status) = "test" Or LCase(clsPlugin.Status) = "fake" Then litFakeOrTest.Visible = True Else litFakeOrTest.Visible = False
End If
Dim blnBasketAllDigital As Boolean = UC_BasketSummary.GetBasket.AllDigital
If mvwCheckout.ActiveViewIndex = "1" Then
'=======================================
'ADDRESS DETAILS ENTERED,
'SHIPPING METHODS SELECTED
'COMMENTS ADDED
'=======================================
litOtherErrors.Text = ""
'Handle EU VAT number validation
Dim blnValidEUVAT As Boolean
If txtEUVAT.Visible And Not String.IsNullOrEmpty(txtEUVAT.Text) Then
txtEUVAT_AutoPostback()
blnValidEUVAT = Session("blnEUVATValidated")
If Not blnValidEUVAT Then litOtherErrors.Text = GetGlobalResourceObject("Kartris", "ContentText_VATNumberInvalid")
Else
blnValidEUVAT = True
End If
'Validation - no shipping selected
If Not UC_BasketView.GetBasket.AllFreeShipping And UC_BasketView.SelectedShippingID = 0 Then
litOtherErrors.Text += GetGlobalResourceObject("Checkout", "ContentText_NoShippingSelected") & "<br />"
End If
If Not _blnAnonymousCheckout Then
'Validation - no billing address
If UC_BillingAddress.SelectedAddress Is Nothing Then
litOtherErrors.Text += GetGlobalResourceObject("Checkout", "ContentText_NoBillingAddress") & "<br />"
blnValidEUVAT = False
End If
End If
If Not blnBasketAllDigital Then
'Validation - no shipping address
If Not chkSameShippingAsBilling.Checked Then
If UC_ShippingAddress.SelectedAddress Is Nothing Then
litOtherErrors.Text += GetGlobalResourceObject("Checkout", "ContentText_NoShippingAddress") & "<br />"
blnValidEUVAT = False
End If
End If
End If
'Validation - Ts and Cs agreement not checked
If GetKartConfig("frontend.checkout.termsandconditions") <> "n" Then
If Not chkTermsAndConditions.Checked Then
litOtherErrors.Text += GetGlobalResourceObject("Checkout", "ContentText_ErrorTermsNotChecked") & "<br />"
blnValidEUVAT = False
End If
End If
'=======================================
'PAGE IS VALID
'Set up confirmation page
'=======================================
If Page.IsValid And (UC_BasketView.SelectedShippingID <> 0 Or UC_BasketView.GetBasket.AllFreeShipping) And blnValidEUVAT Then
Dim isOk As Boolean = True
'Set billing address to one selected by user
'Set shipping address to this, or to selected shipping one, depending on same-shipping checkbox
If Not blnBasketAllDigital Then
If Not _blnAnonymousCheckout AndAlso UC_BillingAddress.SelectedAddress IsNot Nothing Then
If chkSameShippingAsBilling.Checked Then
UC_Shipping.Address = UC_BillingAddress.SelectedAddress
Else
UC_Shipping.Address = UC_ShippingAddress.SelectedAddress
End If
Else
UC_Shipping.Address = UC_ShippingAddress.SelectedAddress
End If
Else
If Not _blnAnonymousCheckout Then
'For downloable orders, we don't really need shipping, but
'payment systems require it. Therefore, we set it to same
'as billing and also check the box (which is hidden) to say
'we're using same shipping address as for billing
UC_Shipping.Address = UC_BillingAddress.SelectedAddress
chkSameShippingAsBilling.Checked = True
End If
End If
If _blnAnonymousCheckout Then
UC_Billing.Visible = False
litBillingDetails.Visible = False
Else
UC_Billing.Address = UC_BillingAddress.SelectedAddress
UC_Billing.Visible = True
litBillingDetails.Visible = True
End If
'Hide shipping address from being visible if all items in order
'are downloadable
If blnBasketAllDigital Then
UC_Shipping.Visible = False
litShippingDetails.Visible = False
Else
UC_Shipping.Visible = True
litShippingDetails.Visible = True
End If
'Show payment method on confirmation page
If _SelectedPaymentMethod.ToLower = "po_offlinepayment" Then
'Change 'po_offlinepayment' to language string for this payment type
litPaymentMethod.Text = Server.HtmlEncode(GetGlobalResourceObject("Checkout", "ContentText_Po"))
litPONumberText.Text = GetGlobalResourceObject("Invoice", "ContentText_PONumber") & ": <strong>" & txtPurchaseOrderNo.Text & "</strong><br/>"
Else
'try to get the friendly name - use the payment gateway name if its blank
Dim strFriendlyName As String = Payment.GetPluginFriendlyName(strGatewayName)
If Interfaces.Utils.TrimWhiteSpace(strFriendlyName) <> "" Then
litPaymentMethod.Text = strFriendlyName
Else
litPaymentMethod.Text = _SelectedPaymentMethod
End If
End If
'Show PO number
If txtPurchaseOrderNo.Text = "" Then
litPONumberText.Text = ""
End If
'Show VAT number
If txtEUVAT.Text <> "" Then
litVATNumberText.Text = GetGlobalResourceObject("Invoice", "FormLabel_CardholderEUVatNum") & ": <strong>" & txtEUVAT.Text & "</strong><br/>"
End If
'Show VAT number
If txtEORI.Text <> "" Then
litEORINumberText.Text = "EORI: <strong>" & txtEORI.Text & "</strong><br/>"
End If
'Show whether mailing list opted into
If Not chkMailingList.Checked Then litMailingListYes.Visible = False Else litMailingListYes.Visible = True
'Show whether 'receive order updates' was checked
If Not chkOrderEmails.Checked Then litOrderEmailsYes2.Visible = False Else litOrderEmailsYes2.Visible = True
'Show whether 'save basket' was checked
If Not chkSaveBasket.Checked Then litSaveBasketYes.Visible = False Else litSaveBasketYes.Visible = True
'Show comments (HTMLencoded for XSS protection)
If Trim(txtComments.Text) <> "" Then
lblComments.Text = Server.HtmlEncode(CkartrisDisplayFunctions.StripHTML(txtComments.Text))
pnlComments.Visible = True
Else
pnlComments.Visible = False
End If
'Set various variables for use later
Dim CUR_ID As Integer = CInt(Session("CUR_ID"))
Dim objBasket As Kartris.Basket = Session("Basket")
'Some items might be excluded from customer discount
If objBasket.HasCustomerDiscountExemption Then
End If
Dim intGatewayCurrency As Int16
'Set payment gateway
If Interfaces.Utils.TrimWhiteSpace(clsPlugin.Currency) <> "" Then
intGatewayCurrency = CurrenciesBLL.CurrencyID(clsPlugin.Currency)
Else
intGatewayCurrency = CUR_ID
End If
'If payment system can only process a particular currency
'we show a message that the order was converted from user
'selected currency to this for processing
If intGatewayCurrency <> CUR_ID Then
pnlProcessCurrency.Visible = True
lblProcessCurrency.Text = CurrenciesBLL.FormatCurrencyPrice(intGatewayCurrency, CurrenciesBLL.ConvertCurrency(intGatewayCurrency, objBasket.FinalPriceIncTax, CUR_ID), , False)
Else
pnlProcessCurrency.Visible = False
End If
'Back button, in case customers need to change anything
btnBack.Visible = True
'Show Credit Card Input Usercontrol if payment gateway type is local
If LCase(clsPlugin.GatewayType) = "local" And
Not (clsPlugin.GatewayName.ToLower = "po_offlinepayment" Or
clsPlugin.GatewayName.ToLower = "bitcoin") Then
UC_CreditCardInput.AcceptsPaypal = clsPlugin.AcceptsPaypal
phdCreditCardInput.Visible = True
Else
phdCreditCardInput.Visible = False
End If
If isOk Then
'Move to next step
mvwCheckout.ActiveViewIndex = "2"
btnProceed.OnClientClick = ""
End If
Else
'Show any errors not handled by
'client side validation
popExtender.Show()
End If
ElseIf mvwCheckout.ActiveViewIndex = "2" Then
'=======================================
'PROCEED CLICKED ON ORDER REVIEW PAGE
'=======================================
Dim blnValid As Boolean = False
Dim numSelectedShippingID As Integer = 0
Try
numSelectedShippingID = UC_BasketView.SelectedShippingID
Catch ex As Exception
End Try
'If numSelectedShippingID = 0 Then Response.Redirect("Checkout.aspx?shippingzero")
'This causes issues with shipping selection, drop it for now
'Load the basket again to verify contents. Check if quantities are still valid
'UC_BasketSummary.LoadBasket()
'Dim objValidateBasket As Kartris.Basket = UC_BasketSummary.GetBasket
'If objValidateBasket.AdjustedQuantities Then
' UC_BasketView.LoadBasket()
' mvwCheckout.ActiveViewIndex = "1"
' Exit Sub
'End If
'objValidateBasket = Nothing
'For local payment gateway types, credit
'card details were entered. Validate these.
If phdCreditCardInput.Visible Then
'Validate Credit Card Input here
Page.Validate("CreditCard")
If IsValid Then blnValid = True
End If
'Handle local payment scenarios
'This could be a local type payment gateway
'where card data is entered directly into
'Kartris. Or it could be the PO (purchase
'order) / offline payment method, where a
'user can checkout without giving card
'details and will pay offline.
If LCase(clsPlugin.GatewayType) <> "local" Or
blnValid Or clsPlugin.GatewayName.ToLower = "po_offlinepayment" Or
clsPlugin.GatewayName.ToLower = "bitcoin" Then
'Setup variables to use later
Dim C_ID As Integer = 0
Dim O_ID As Integer
Dim CUR_ID As Integer = CInt(Session("CUR_ID"))
Dim blnUseHTMLOrderEmail As Boolean = (GetKartConfig("general.email.enableHTML") = "y")
Dim sbdHTMLOrderEmail As StringBuilder = New StringBuilder
Dim sbdHTMLOrderContents As StringBuilder = New StringBuilder
Dim sbdHTMLOrderBasket As StringBuilder = New StringBuilder
'Dim strBillingAddressText As String, strShippingAddressText As String
Dim strSubject As String = ""
Dim strTempEmailTextHolder As String = ""
Dim sbdNewCustomerEmailText As StringBuilder = New StringBuilder
Dim sbdBodyText As StringBuilder = New StringBuilder
Dim sbdBasketItems As StringBuilder = New StringBuilder
Dim arrBasketItems As List(Of Kartris.BasketItem)
Dim objBasket As Kartris.Basket = Session("Basket")
Dim objOrder As Kartris.Interfaces.objOrder = Nothing
Dim blnNewUser As Boolean = True