Browse Source

the code..

dfstorm 3 months ago
parent
commit
dc6fabe064
1 changed files with 164 additions and 0 deletions
  1. 164
    0
      index.php

+ 164
- 0
index.php View File

@@ -0,0 +1,164 @@
1
+<?php
2
+	/*
3
+		# payline.com dev relay
4
+		============================================
5
+		
6
+		## Why ?
7
+		Payline doesn't allow any call from localhost and
8
+		most of dev naming uri. So... For dev purpose only
9
+		I make one of my server with a fully qualified
10
+		domain do the work with this script. Productions
11
+		servers won't ever use that relay.
12
+		
13
+		It's not allowed to make card data transit trough
14
+		your servers in production context.
15
+	
16
+	*/
17
+	header('Content-Type: application/json');
18
+	header("Access-Control-Allow-Origin: *");
19
+	class ksportRelay {
20
+		public $rInput = array(
21
+			"accessKeyRef"			=> null,
22
+			"data"					=> null,
23
+			"cardNumber"			=> null,
24
+			"cardExpirationDate"	=> null,
25
+			"cardCvx"				=> null
26
+		);
27
+		private $rCredential  = array(
28
+			"uri" => "https://homologation-webpayment.payline.com/webpayment/getToken",
29
+			"appUser" => "",
30
+			"appSecret" => "",
31
+			"bearer" => "",
32
+			"bearerUri" => "https://api.sandbox.mangopay.com/v2.01/oauth/token/"
33
+		);
34
+		public $rResponse = array(
35
+			"iSatusCode"	=> 0,
36
+			"sMessage"		=> "",
37
+			"sPayload"		=> ""
38
+		);
39
+		function __construct() {
40
+			if ($this->input()) {
41
+				// If inputs are valids, then
42
+				
43
+				// Get auth token.
44
+				$this->getAuthTwo();
45
+				
46
+				// Ask to the card registration.
47
+				$this->send();
48
+				
49
+			} else {
50
+				// Invalid input.
51
+				$this->rResponse["iSatusCode"] = -1;
52
+				$this->rResponse["sMessage"] = "Invalid input";
53
+				
54
+			}
55
+			// display results.
56
+			echo json_encode($this->rResponse);
57
+		}
58
+		
59
+		// Get auth tocken
60
+		function getAuthTwo() {
61
+		
62
+			// Build security header
63
+			$securityHeader = base64_encode($this->rCredential["appUser"].
64
+				':'.$this->rCredential["appSecret"]);
65
+				
66
+			// Init curl request
67
+			$resURL = curl_init(); 
68
+			
69
+			// Set destination for the request
70
+			curl_setopt($resURL, CURLOPT_URL, $this->rCredential["bearerUri"]); 
71
+			
72
+			// Set headers
73
+			curl_setopt($resURL,CURLOPT_HTTPHEADER,array (
74
+				"Authorization: Basic ".$securityHeader,
75
+        		/*"Content-Type: application/x-www-form-urlencoded;" 
76
+        		warning: Documentation tell to put that here. 
77
+        		It's an error on their end. */
78
+    		));
79
+    		
80
+    		// Set type of resquest.
81
+    		curl_setopt($resURL, CURLOPT_POST, 1);
82
+    		
83
+    		// Add post data to the request
84
+    		curl_setopt($resURL, CURLOPT_POSTFIELDS, "grant_type=client_credentials"); 
85
+    		
86
+    		// Tell we want to collect the response
87
+    		curl_setopt($resURL, CURLOPT_RETURNTRANSFER, 1);
88
+    		
89
+    		// Get the response
90
+    		$response = json_decode(curl_exec($resURL), true);
91
+    		
92
+			// Set the token for futur uses.
93
+    		$this->rCredential["bearer"] = $response["access_token"];
94
+    		
95
+    		
96
+		}
97
+		
98
+		// Ask for the card registration
99
+		function send() {
100
+			
101
+	
102
+			// init curl request
103
+			$resURL = curl_init(); 
104
+			
105
+			// Set curl destination
106
+			curl_setopt($resURL, CURLOPT_URL, $this->rCredential["uri"]); 
107
+			
108
+			// Set curl headers
109
+			curl_setopt($resURL,CURLOPT_HTTPHEADER,array (
110
+				"Authorization: Bearer ".$this->rCredential["bearer"],
111
+        		"Content-Type: application/x-www-form-urlencoded"
112
+        		
113
+    		));
114
+    		
115
+    		// Define type of curl request (POST)
116
+    		curl_setopt($resURL, CURLOPT_POST, 1);
117
+    		
118
+    		// Build and Add post data to the request
119
+    		curl_setopt($resURL, CURLOPT_POSTFIELDS, http_build_query($this->rInput));
120
+    		
121
+    		// Tell we want the response data
122
+    		curl_setopt($resURL, CURLOPT_RETURNTRANSFER, 1);
123
+    		
124
+    		// Execute the curl request and get datas.
125
+    		$this->rResponse["sPayload"] = curl_exec($resURL);
126
+    		
127
+    		// If request is successuff
128
+    		if (curl_getinfo($resURL, CURLINFO_HTTP_CODE) == 200) {
129
+    			// if yes
130
+				$this->rResponse["sMessage"] = "SUCCESS (Everything where good on our end payline.com still may crash remotely... Please test the payload";
131
+    		} else {
132
+    			// if it's not
133
+    			$this->rResponse["iSatusCode"] = -2;
134
+				$this->rResponse["sMessage"] = "Post resquest failed";
135
+    		}
136
+    		
137
+    		// close connection.
138
+    		curl_close($resURL);
139
+		}
140
+		
141
+		// Validate post input.
142
+		function input() {
143
+			if (
144
+				isset($_POST['accessKeyRef']) &&
145
+				isset($_POST['data']) &&
146
+				isset($_POST['cardNumber']) &&
147
+				isset($_POST['cardExpirationDate']) &&
148
+				isset($_POST['cardCvx'])
149
+			) {
150
+				$this->rInput["accessKeyRef"]		= $_POST['accessKeyRef'];
151
+				$this->rInput["data"]				= $_POST['data'];
152
+				$this->rInput["cardNumber"]			= $_POST['cardNumber'];
153
+				$this->rInput["cardExpirationDate"]	= $_POST['cardExpirationDate'];
154
+				$this->rInput["cardCvx"]			= $_POST['cardCvx'];
155
+				return true;
156
+			} else {
157
+				return false;
158
+			}
159
+		}
160
+	}
161
+	
162
+	$ksport = new ksportRelay();
163
+
164
+

Loading…
Cancel
Save