· 6 years ago · Apr 24, 2019, 01:46 PM
1
2function mycred_pagamento( $user_email_from, $user_email_to, $user_email, $reference, $entry, $amount, $tipo_pagamento ) {
3
4
5$secret_key = ':Tzq({QXiE;_elk;';
6$remote_url = 'https://www.raceroomers.pt/mycred-api/';
7//$user_atual = get_current_user_id();
8$profile_id = um_profile_id();
9
10$transactionId = 'TXID' . current_time( 'timestamp' ) . $profile_id;
11
12echo '<script language="javascript">alert("'. $amount . '")</script>';
13
14echo "<br>pagamento de: " . $user_email_from . " para " . $user_email_to . " ref: " . $reference . " entry: " . $entry . " amount: " . $amount . " tp: " . $tipo_pagamento;
15
16 switch ($tipo_pagamento) {
17
18 case 0: // GET
19
20 $action = 'GET';
21 $account = $user_email;
22 $point_type = 'mycred_default';
23 $host = get_bloginfo( 'url' );
24 $token = md5( $host . $action . $secret_key );
25
26 $request = array(
27 'method' => 'POST',
28 'body' => array(
29 'action' => $action,
30 'account' => $account,
31 'type' => $point_type,
32 'token' => $token,
33 'host' => $host
34 )
35 );
36
37 $response = wp_remote_post( $remote_url, $request );
38
39 break;
40
41
42 case 1: // CREDIT
43 $action = 'CREDIT';
44 $account = $user_email;
45 $amount = $amount;
46 $ref = $reference;
47 $ref_id = $transactionId;
48 $entry = $entry;
49 $data = 'optional extra';
50 $point_type = 'mycred_default';
51 $host = get_bloginfo( 'url' );
52
53 $token = md5( $host . $action . $amount . $secret_key );
54
55 $request = array(
56 'method' => 'POST',
57 'body' => array(
58 'action' => $action,
59 'account' => $account,
60 'amount' => $amount,
61 'ref' => $ref,
62 'ref_id' => $ref_id,
63 'type' => $point_type,
64 'entry' => $entry,
65 'data' => $data,
66 'token' => $token,
67 'host' => $host
68 )
69 );
70
71 $response = wp_remote_post( $remote_url, $request );
72
73 break;
74
75
76
77 case 2: // DEBIT
78
79
80 $action = 'DEBIT';
81 $account = $user_email;
82 $amount = $amount;
83 $ref = $reference;
84 $point_type = 'mycred_default';
85 $ref_id = $transactionId;
86 $entry = $entry;
87 $data = 'optional extra';
88 $host = get_bloginfo( 'url' );
89 $token = md5( $host . $action . $amount . $secret_key );
90
91 $request = array(
92 'method' => 'POST',
93 'body' => array(
94 'action' => $action,
95 'account' => $account,
96 'amount' => $amount,
97 'ref' => $ref,
98 'ref_id' => $ref_id,
99 'type' => $point_type,
100 'entry' => $entry,
101 'data' => $data,
102 'token' => $token,
103 'host' => $host
104 )
105 );
106
107
108
109 $response = wp_remote_post( $remote_url, $request );
110
111 break;
112
113
114 case 3: // PAY
115
116 echo '<script language="javascript">alert("'. $amount . '")</script>';
117
118 $action = 'PAY';
119 $from = $user_email_from;
120 $amount = $amount;
121 $to = $user_email_to;
122 $ref = $reference;
123 $ref_id = $transactionId;
124 $entry = $entry;
125 $data = 'optional extra';
126 $point_type = 'mycred_default';
127 $host = get_bloginfo( 'url' );
128
129 $token = md5( $host . $action . $amount . $from . $to . $secret_key );
130
131 $request = array(
132 'method' => 'POST',
133 'body' => array(
134 'action' => $action,
135 'account' => $from,
136 'amount' => $amount,
137 'to' => $to,
138 'ref' => $ref,
139 'ref_id' => $ref_id,
140 'type' => $point_type,
141 'entry' => $entry,
142 'data' => $data,
143 'token' => $token,
144 'host' => $host
145 )
146 );
147
148 $response = wp_remote_post( $remote_url, $request );
149
150 break;
151 }
152
153
154}