@@ -8,62 +8,123 @@ export default Component.extend({
8
8
9
9
async didInsertElement ( ) {
10
10
this . _super ( ...arguments ) ;
11
- let order = this . data ;
12
- let createPayload = {
13
- 'data' : {
14
- 'attributes' : {
15
- 'return-url' : `${ window . location . origin } /orders/${ order . identifier } /view` ,
16
- 'cancel-url' : `${ window . location . origin } /orders/${ order . identifier } /pending`
11
+ if ( this . paymentFor === 'order' ) {
12
+ let order = this . data ;
13
+ let createPayload = {
14
+ 'data' : {
15
+ 'attributes' : {
16
+ 'return-url' : `${ window . location . origin } /orders/${ order . identifier } /view` ,
17
+ 'cancel-url' : `${ window . location . origin } /orders/${ order . identifier } /pending`
18
+ } ,
19
+ 'type' : 'paypal-payment'
20
+ }
21
+ } ;
22
+
23
+ paypal . Button . render ( {
24
+ commit : true ,
25
+
26
+ style : {
27
+ label : 'pay' ,
28
+ size : 'medium' , // tiny, small, medium
29
+ color : 'gold' , // orange, blue, silver
30
+ shape : 'pill' // pill, rect
17
31
} ,
18
- 'type' : 'paypal-payment'
19
- }
20
- } ;
21
32
22
- paypal . Button . render ( {
23
- commit : true ,
33
+ payment : ( ) => {
34
+ return this . loader . post ( `orders/${ order . identifier } /create-paypal-payment` , createPayload )
35
+ . then ( res => {
36
+ return res . payment_id ;
37
+ } ) ;
38
+ } ,
39
+
40
+ onAuthorize : data => {
41
+ // this callback will be for authorizing the payments
42
+ let chargePayload = {
43
+ 'data' : {
44
+ 'attributes' : {
45
+ 'stripe' : null ,
46
+ 'paypal_payer_id' : data . payerID ,
47
+ 'paypal_payment_id' : data . paymentID
48
+ } ,
49
+ 'type' : 'charge'
50
+ }
51
+ } ;
52
+ let config = {
53
+ skipDataTransform : true
54
+ } ;
55
+ chargePayload = JSON . stringify ( chargePayload ) ;
56
+ return this . loader . post ( `orders/${ order . identifier } /charge` , chargePayload , config )
57
+ . then ( charge => {
58
+ if ( charge . data . attributes . status ) {
59
+ this . notify . success ( charge . data . attributes . message ) ;
60
+ this . router . transitionTo ( 'orders.view' , order . identifier ) ;
61
+ } else {
62
+ this . notify . error ( charge . data . attributes . message ) ;
63
+ }
64
+ } ) ;
65
+ }
66
+
67
+ } , this . elementId ) ;
24
68
25
- style : {
26
- label : 'pay' ,
27
- size : 'medium' , // tiny, small, medium
28
- color : 'gold' , // orange, blue, silver
29
- shape : 'pill' // pill, rect
30
- } ,
69
+ } else if ( this . paymentFor === 'invoice' ) {
70
+ let eventInvoice = this . data ;
71
+ let createPayload = {
72
+ 'data' : {
73
+ 'attributes' : {
74
+ 'return-url' : `${ window . location . origin } /event-invoice/${ eventInvoice . identifier } /paid` ,
75
+ 'cancel-url' : `${ window . location . origin } /event-invoice/${ eventInvoice . identifier } /pending`
76
+ } ,
77
+ 'type' : 'paypal-payment'
78
+ }
79
+ } ;
80
+ paypal . Button . render ( {
81
+ env : 'sandbox' ,
82
+ commit : true ,
31
83
32
- payment : ( ) => {
33
- return this . loader . post ( `orders/ ${ order . identifier } /create-paypal-payment` , createPayload )
34
- . then ( res => {
35
- return res . payment_id ;
36
- } ) ;
37
- } ,
84
+ style : {
85
+ label : 'pay' ,
86
+ size : 'medium' , // tiny, small, medium
87
+ color : 'gold' , // orange, blue, silver
88
+ shape : 'pill' // pill, rect
89
+ } ,
38
90
39
- onAuthorize : data => {
40
- // this callback will be for authorizing the payments
41
- let chargePayload = {
42
- 'data' : {
43
- 'attributes' : {
44
- 'stripe' : null ,
45
- 'paypal_payer_id' : data . payerID ,
46
- 'paypal_payment_id' : data . paymentID
47
- } ,
48
- 'type' : 'charge'
49
- }
50
- } ;
51
- let config = {
52
- skipDataTransform : true
53
- } ;
54
- chargePayload = JSON . stringify ( chargePayload ) ;
55
- return this . loader . post ( `orders/${ order . identifier } /charge` , chargePayload , config )
56
- . then ( charge => {
57
- if ( charge . data . attributes . status ) {
58
- this . notify . success ( charge . data . attributes . message ) ;
59
- this . router . transitionTo ( 'orders.view' , order . identifier ) ;
60
- } else {
61
- this . notify . error ( charge . data . attributes . message ) ;
91
+ payment : ( ) => {
92
+ return this . loader . post ( `event-invoices/${ eventInvoice . identifier } /create-paypal-payment` , createPayload )
93
+ . then ( res => {
94
+ return res . payment_id ;
95
+ } ) ;
96
+ } ,
97
+
98
+ onAuthorize : data => {
99
+ // this callback will be for authorizing the payments
100
+ let chargePayload = {
101
+ 'data' : {
102
+ 'attributes' : {
103
+ 'stripe' : null ,
104
+ 'paypal_payer_id' : data . payerID ,
105
+ 'paypal_payment_id' : data . paymentID
106
+ } ,
107
+ 'type' : 'charge'
62
108
}
63
- } ) ;
64
- }
109
+ } ;
110
+ let config = {
111
+ skipDataTransform : true
112
+ } ;
113
+ chargePayload = JSON . stringify ( chargePayload ) ;
114
+ return this . loader . post ( `event-invoices/${ eventInvoice . identifier } /charge` , chargePayload , config )
115
+ . then ( charge => {
116
+ if ( charge . status ) {
117
+ this . notify . success ( charge . status ) ;
118
+ this . router . transitionTo ( 'event-invoice.paid' , eventInvoice . identifier ) ;
119
+ } else {
120
+ this . notify . error ( charge . error ) ;
121
+ }
122
+ } ) ;
123
+ }
124
+
125
+ } , this . elementId ) ;
65
126
66
- } , this . elementId ) ;
67
127
128
+ }
68
129
}
69
130
} ) ;
0 commit comments