1
+ <div x-data =" {
2
+ {{-- We use AlpineJs modelling here as we do not want the card details to go up to Livewire. --}}
3
+ name: '{{ $this -> billing -> first_name } } {{ $this -> billing -> last_name } } ',
4
+ card: '4929000000006',
5
+ expiry: '1232',
6
+ cvv: '123',
7
+ processing: @entangle (' processing' ),
8
+ {{-- This is the tokenised card we need to send up to Livewire --}}
9
+ identifier: @entangle (' identifier' ),
10
+ merchantKey: @entangle (' merchantKey' ),
11
+ errors: [],
12
+ init() {
13
+ window.addEventListener('opayo_threed_secure_response', e => {
14
+ $wire.call('processThreed', {
15
+ mdx: e.detail.mdx,
16
+ md: e.detail.md,
17
+ pares: e.detail.PaRes,
18
+ cres: e.detail.cres
19
+ })
20
+ });
21
+ },
22
+ handleSubmit () {
23
+ this.errors = []
24
+ this.processing = true
25
+
26
+ const date = new Date();
27
+ const tzOffset = date.getTimezoneOffset();
28
+
29
+ let screenSize = 'Large';
30
+
31
+ if (window.outerWidth < 400) {
32
+ screenSize = 'Small';
33
+ }
34
+
35
+ if (window.outerWidth < 800) {
36
+ screenSize = 'Medium';
37
+ }
38
+
39
+ $wire.set('browser', {
40
+ browserLanguage: navigator.language,
41
+ challengeWindowSize: screenSize,
42
+ browserUserAgent: navigator.userAgent,
43
+ browserJavaEnabled: navigator.javaEnabled(),
44
+ browserColorDepth: window.screen.colorDepth,
45
+ browserScreenHeight: window.outerHeight,
46
+ browserScreenWidth: window.outerWidth,
47
+ browserTZ: tzOffset,
48
+ })
49
+
50
+ sagepayOwnForm({
51
+ merchantSessionKey: this.merchantKey,
52
+ }).tokeniseCardDetails({
53
+ onTokenised: (result) => {
54
+ if (!result.success) {
55
+ this.errors = result.errors
56
+ this.processing = false
57
+ return
58
+ }
59
+
60
+ $wire.set('identifier', result.cardIdentifier)
61
+ $wire.set('sessionKey', this.merchantKey)
62
+ $wire.call('process')
63
+ },
64
+ cardDetails: {
65
+ cardholderName: this.name,
66
+ cardNumber: this.card,
67
+ expiryDate: this.expiry,
68
+ securityCode: this.cvv,
69
+ }
70
+ })
71
+ }
72
+ }" >
73
+ @if ($showChallenge )
74
+ @include (' getcandy::opayo.partials.threed-secure-modal' )
75
+ @endif
76
+
77
+ <form class =" space-y-2" x-on:submit.prevent =" handleSubmit()" >
78
+ <label class =" space-y-1" >
79
+ <span class =" text-sm font-medium" >Cardholder Name</span >
80
+ <input type =" text" x-model =" name" class =" w-full border-gray-300 rounded shadow-sm" />
81
+ </label >
82
+ <div class =" flex space-x-2" >
83
+ <label class =" space-y-1 grow" >
84
+ <span class =" text-sm font-medium" >Card Number</span >
85
+ <input type =" number" x-model =" card" class =" w-full border-gray-300 rounded shadow-sm" placeholder =" 0000 0000 0000 0000" />
86
+ </label >
87
+
88
+ <label class =" w-24 space-y-1" >
89
+ <span class =" text-sm font-medium" >CVV</span >
90
+ <input type =" number" x-model =" cvv" class =" w-full border-gray-300 rounded shadow-sm" placeholder =" 123" />
91
+ </label >
92
+
93
+ <label class =" w-24 space-y-1" >
94
+ <span class =" text-sm font-medium" >Expiry</span >
95
+ <input type =" text" x-model =" expiry" class =" w-full border-gray-300 rounded shadow-sm" placeholder =" MM/YY" />
96
+ </label >
97
+ </div >
98
+
99
+ <button
100
+ class =" flex items-center px-5 py-3 text-sm font-medium text-white bg-blue-600 rounded-lg hover:bg-blue-500 disabled:opacity-50"
101
+ type =" submit"
102
+ x-bind:disabled =" processing"
103
+ >
104
+ <span
105
+ x-show =" !processing"
106
+ >
107
+ Make Payment
108
+ </span >
109
+ <span
110
+ x-show =" processing"
111
+ class =" block mr-2"
112
+ >
113
+ <svg
114
+ class =" w-5 h-5 text-white animate-spin"
115
+ xmlns =" http://www.w3.org/2000/svg"
116
+ fill =" none"
117
+ viewBox =" 0 0 24 24"
118
+ >
119
+ <circle
120
+ class =" opacity-25"
121
+ cx =" 12"
122
+ cy =" 12"
123
+ r =" 10"
124
+ stroke =" currentColor"
125
+ stroke-width =" 4"
126
+ ></circle >
127
+ <path
128
+ class =" opacity-75"
129
+ fill =" currentColor"
130
+ d =" M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
131
+ ></path >
132
+ </svg >
133
+ </span >
134
+ <span
135
+ x-show =" processing"
136
+ >
137
+ Processing
138
+ </span >
139
+ </button >
140
+ </form >
141
+
142
+ <div x-show =" errors.length" class =" p-4 mt-4 space-y-2 rounded bg-red-50" x-cloak >
143
+ <template x-for =" (error, errorIndex) in errors" :key =" errorIndex" hidden >
144
+ <span x-text =" error.message" class =" block text-red-600" ></span >
145
+ </template >
146
+ </div >
147
+ </div >
0 commit comments