Browse Source

the code..

master
dfstorm 1 year ago
parent
commit
dc6fabe064
  1. 164
      index.php

164
index.php

@ -0,0 +1,164 @@
<?php
/*
# payline.com dev relay
============================================
## Why ?
Payline doesn't allow any call from localhost and
most of dev naming uri. So... For dev purpose only
I make one of my server with a fully qualified
domain do the work with this script. Productions
servers won't ever use that relay.
It's not allowed to make card data transit trough
your servers in production context.
*/
header('Content-Type: application/json');
header("Access-Control-Allow-Origin: *");
class ksportRelay {
public $rInput = array(
"accessKeyRef" => null,
"data" => null,
"cardNumber" => null,
"cardExpirationDate" => null,
"cardCvx" => null
);
private $rCredential = array(
"uri" => "https://homologation-webpayment.payline.com/webpayment/getToken",
"appUser" => "",
"appSecret" => "",
"bearer" => "",
"bearerUri" => "https://api.sandbox.mangopay.com/v2.01/oauth/token/"
);
public $rResponse = array(
"iSatusCode" => 0,
"sMessage" => "",
"sPayload" => ""
);
function __construct() {
if ($this->input()) {
// If inputs are valids, then
// Get auth token.
$this->getAuthTwo();
// Ask to the card registration.
$this->send();
} else {
// Invalid input.
$this->rResponse["iSatusCode"] = -1;
$this->rResponse["sMessage"] = "Invalid input";
}
// display results.
echo json_encode($this->rResponse);
}
// Get auth tocken
function getAuthTwo() {
// Build security header
$securityHeader = base64_encode($this->rCredential["appUser"].
':'.$this->rCredential["appSecret"]);
// Init curl request
$resURL = curl_init();
// Set destination for the request
curl_setopt($resURL, CURLOPT_URL, $this->rCredential["bearerUri"]);
// Set headers
curl_setopt($resURL,CURLOPT_HTTPHEADER,array (
"Authorization: Basic ".$securityHeader,
/*"Content-Type: application/x-www-form-urlencoded;"
warning: Documentation tell to put that here.
It's an error on their end. */
));
// Set type of resquest.
curl_setopt($resURL, CURLOPT_POST, 1);
// Add post data to the request
curl_setopt($resURL, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
// Tell we want to collect the response
curl_setopt($resURL, CURLOPT_RETURNTRANSFER, 1);
// Get the response
$response = json_decode(curl_exec($resURL), true);
// Set the token for futur uses.
$this->rCredential["bearer"] = $response["access_token"];
}
// Ask for the card registration
function send() {
// init curl request
$resURL = curl_init();
// Set curl destination
curl_setopt($resURL, CURLOPT_URL, $this->rCredential["uri"]);
// Set curl headers
curl_setopt($resURL,CURLOPT_HTTPHEADER,array (
"Authorization: Bearer ".$this->rCredential["bearer"],
"Content-Type: application/x-www-form-urlencoded"
));
// Define type of curl request (POST)
curl_setopt($resURL, CURLOPT_POST, 1);
// Build and Add post data to the request
curl_setopt($resURL, CURLOPT_POSTFIELDS, http_build_query($this->rInput));
// Tell we want the response data
curl_setopt($resURL, CURLOPT_RETURNTRANSFER, 1);
// Execute the curl request and get datas.
$this->rResponse["sPayload"] = curl_exec($resURL);
// If request is successuff
if (curl_getinfo($resURL, CURLINFO_HTTP_CODE) == 200) {
// if yes
$this->rResponse["sMessage"] = "SUCCESS (Everything where good on our end payline.com still may crash remotely... Please test the payload";
} else {
// if it's not
$this->rResponse["iSatusCode"] = -2;
$this->rResponse["sMessage"] = "Post resquest failed";
}
// close connection.
curl_close($resURL);
}
// Validate post input.
function input() {
if (
isset($_POST['accessKeyRef']) &&
isset($_POST['data']) &&
isset($_POST['cardNumber']) &&
isset($_POST['cardExpirationDate']) &&
isset($_POST['cardCvx'])
) {
$this->rInput["accessKeyRef"] = $_POST['accessKeyRef'];
$this->rInput["data"] = $_POST['data'];
$this->rInput["cardNumber"] = $_POST['cardNumber'];
$this->rInput["cardExpirationDate"] = $_POST['cardExpirationDate'];
$this->rInput["cardCvx"] = $_POST['cardCvx'];
return true;
} else {
return false;
}
}
}
$ksport = new ksportRelay();
Loading…
Cancel
Save