Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class CurlRequest
- {
- public static function post($url, $data, $headers=[], $user=false)
- {
- foreach ($data as &$d) {
- $d = urlencode($d);
- }
- $fields_string = "";
- foreach($data as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
- curl_setopt($ch,CURLOPT_POST, count($data));
- if ($user) {
- curl_setopt($ch, CURLOPT_USERPWD, $user);
- }
- curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
- $q = curl_exec($ch);
- $q2 = curl_getinfo($ch,CURLINFO_HTTP_CODE);
- curl_close($ch);
- if ($q2 == 200) {
- return $q;
- } else {
- return false;
- }
- }
- public static function get($url, $data, $headers=[])
- {
- foreach ($data as &$d) {
- $d = urlencode($d);
- }
- $fields_string = "";
- foreach($data as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
- $ch = curl_init($url."?".$fields_string);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
- $q = curl_exec($ch);
- curl_close($ch);
- return $q;
- }
- }
- class PayPal
- {
- private $clientId;
- private $clientSecret;
- private $accessToken;
- public function __construct($clientId, $clientSecret)
- {
- $this->clientId = $clientId;
- $this->clientSecret = $clientSecret;
- $q = CurlRequest::post("https://api.sandbox.paypal.com/v1/oauth2/token",["grant_type" => "client_credentials"],["Accept: application/json"],$clientId.":".$clientSecret);
- if($q) {
- $q = json_decode($q,true);
- $this->accessToken = $q['access_token'];
- echo $this->accessToken;
- }
- }
- public function pay()
- {
- $q = CurlRequest::post("",["access_token" => $this->accessToken, "amount" => ]);
- }
- }
- $p = new PayPal("AQr-2Wl1kauMouHhW95aJzQLWjHUuypVq4O1WV3tXrZ9zixW9-Qcdtil-fNYsrDjtQ8JoCAFBiCCh3ah","EJ49tuWUksfOhUc-2hFghE-P1ncwTL_dKsZbHN3A--A7ohIeqj7E9B1Gtq6t_K9tVmfKBvp_qI7sjYEX");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement