Skip to content

Instantly share code, notes, and snippets.

@paulwababu
Last active December 4, 2022 16:41
Show Gist options
  • Save paulwababu/ca28b696763319c2de8b416fe3ad9a2d to your computer and use it in GitHub Desktop.
Save paulwababu/ca28b696763319c2de8b416fe3ad9a2d to your computer and use it in GitHub Desktop.
Capture Order. Aimed to check whether a user has paid or not
var client = new RestClient("https://pesapedia.co.ke/api/v2/paypal/order/capture");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
request.AddHeader("Authorization", "Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e");
request.AlwaysMultipartFormData = true;
request.AddParameter("environment", "sandbox");
request.AddParameter("client_id", "xxx");
request.AddParameter("client_secret", "xxx");
request.AddParameter("url", "https://api.sandbox.paypal.com/v2/checkout/orders/2S71025914161602N/capture");
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
curl --location --request GET 'https://pesapedia.co.ke/api/v2/paypal/order/capture' \
--header 'Authorization: Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e' \
--form 'environment="sandbox"' \
--form 'client_id="xxx"' \
--form 'client_secret="xxx"' \
--form 'url="https://api.sandbox.paypal.com/v2/checkout/orders/2S71025914161602N/capture"'
var headers = {
'Authorization': 'Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e'
};
var request = http.MultipartRequest('GET', Uri.parse('https://pesapedia.co.ke/api/v2/paypal/order/capture'));
request.fields.addAll({
'environment': 'sandbox',
'client_id': 'xxx',
'client_secret': 'xxx',
'url': 'https://api.sandbox.paypal.com/v2/checkout/orders/2S71025914161602N/capture'
});
request.headers.addAll(headers);
http.StreamedResponse response = await request.send();
if (response.statusCode == 200) {
print(await response.stream.bytesToString());
}
else {
print(response.reasonPhrase);
}
package main
import (
"fmt"
"bytes"
"mime/multipart"
"net/http"
"io/ioutil"
)
func main() {
url := "https://pesapedia.co.ke/api/v2/paypal/order/capture"
method := "GET"
payload := &bytes.Buffer{}
writer := multipart.NewWriter(payload)
_ = writer.WriteField("environment", "sandbox")
_ = writer.WriteField("client_id", "xxx")
_ = writer.WriteField("client_secret", "xxx")
_ = writer.WriteField("url", "https://api.sandbox.paypal.com/v2/checkout/orders/2S71025914161602N/capture")
err := writer.Close()
if err != nil {
fmt.Println(err)
return
}
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Authorization", "Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e")
req.Header.Set("Content-Type", writer.FormDataContentType())
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
var myHeaders = new Headers();
myHeaders.append("Authorization", "Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e");
var formdata = new FormData();
formdata.append("environment", "sandbox");
formdata.append("client_id", "xxx");
formdata.append("client_secret", "xxx");
formdata.append("url", "https://api.sandbox.paypal.com/v2/checkout/orders/2S71025914161602N/capture");
var requestOptions = {
method: 'GET',
headers: myHeaders,
body: formdata,
redirect: 'follow'
};
fetch("https://pesapedia.co.ke/api/v2/paypal/order/capture", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
var form = new FormData();
form.append("environment", "sandbox");
form.append("client_id", "xxx");
form.append("client_secret", "xxx");
form.append("url", "https://api.sandbox.paypal.com/v2/checkout/orders/2S71025914161602N/capture");
var settings = {
"url": "https://pesapedia.co.ke/api/v2/paypal/order/capture",
"method": "GET",
"timeout": 0,
"headers": {
"Authorization": "Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e"
},
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};
$.ajax(settings).done(function (response) {
console.log(response);
});
// WARNING: For GET requests, body is set to null by browsers.
var data = new FormData();
data.append("environment", "sandbox");
data.append("client_id", "xxx");
data.append("client_secret", "xxx");
data.append("url", "https://api.sandbox.paypal.com/v2/checkout/orders/2S71025914161602N/capture");
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("GET", "https://pesapedia.co.ke/api/v2/paypal/order/capture");
xhr.setRequestHeader("Authorization", "Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e");
xhr.send(data);
var axios = require('axios');
var FormData = require('form-data');
var data = new FormData();
data.append('environment', 'sandbox');
data.append('client_id', 'xxx');
data.append('client_secret', 'xxx');
data.append('url', 'https://api.sandbox.paypal.com/v2/checkout/orders/2S71025914161602N/capture');
var config = {
method: 'get',
url: 'https://pesapedia.co.ke/api/v2/paypal/order/capture',
headers: {
'Authorization': 'Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e',
...data.getHeaders()
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
var https = require('follow-redirects').https;
var fs = require('fs');
var options = {
'method': 'GET',
'hostname': 'pesapedia.co.ke',
'path': '/api/v2/paypal/order/capture',
'headers': {
'Authorization': 'Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e'
},
'maxRedirects': 20
};
var req = https.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function (chunk) {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
res.on("error", function (error) {
console.error(error);
});
});
var postData = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"environment\"\r\n\r\nsandbox\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"client_id\"\r\n\r\nxxx\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"client_secret\"\r\n\r\nxxx\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"url\"\r\n\r\nhttps://api.sandbox.paypal.com/v2/checkout/orders/2S71025914161602N/capture\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--";
req.setHeader('content-type', 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW');
req.write(postData);
req.end();
var request = require('request');
var options = {
'method': 'GET',
'url': 'https://pesapedia.co.ke/api/v2/paypal/order/capture',
'headers': {
'Authorization': 'Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e'
},
formData: {
'environment': 'sandbox',
'client_id': 'xxx',
'client_secret': 'xxx',
'url': 'https://api.sandbox.paypal.com/v2/checkout/orders/2S71025914161602N/capture'
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
var unirest = require('unirest');
var req = unirest('GET', 'https://pesapedia.co.ke/api/v2/paypal/order/capture')
.headers({
'Authorization': 'Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e'
})
.field('environment', 'sandbox')
.field('client_id', 'xxx')
.field('client_secret', 'xxx')
.field('url', 'https://api.sandbox.paypal.com/v2/checkout/orders/2S71025914161602N/capture')
.end(function (res) {
if (res.error) throw new Error(res.error);
console.log(res.raw_body);
});
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://pesapedia.co.ke/api/v2/paypal/order/capture',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_POSTFIELDS => array('environment' => 'sandbox','client_id' => 'xxx','client_secret' => 'xxx','url' => 'https://api.sandbox.paypal.com/v2/checkout/orders/2S71025914161602N/capture'),
CURLOPT_HTTPHEADER => array(
'Authorization: Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
import requests
url = "https://pesapedia.co.ke/api/v2/paypal/order/capture"
payload={'environment': 'sandbox',
'client_id': 'xxx',
'client_secret': 'xxx',
'url': 'https://api.sandbox.paypal.com/v2/checkout/orders/2S71025914161602N/capture'}
files=[
]
headers = {
'Authorization': 'Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e'
}
response = requests.request("GET", url, headers=headers, data=payload, files=files)
print(response.text)
library(httr)
headers = c(
'Authorization' = 'Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e'
)
body = list(
'environment' = 'sandbox',
'client_id' = 'xxx',
'client_secret' = 'xxx',
'url' = 'https://api.sandbox.paypal.com/v2/checkout/orders/2S71025914161602N/capture'
)
res <- VERB("GET", url = "https://pesapedia.co.ke/api/v2/paypal/order/capture", body = body, add_headers(headers), encode = 'multipart')
cat(content(res, 'text'))
library(RCurl)
headers = c(
"Authorization" = "Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e"
)
params = c(
"environment" = "sandbox",
"client_id" = "xxx",
"client_secret" = "xxx",
"url" = "https://api.sandbox.paypal.com/v2/checkout/orders/2S71025914161602N/capture"
)
res <- getURL("https://pesapedia.co.ke/api/v2/paypal/order/capture", .opts=list(httpheader = headers, followlocation = TRUE))
cat(res)
require "uri"
require "net/http"
url = URI("https://pesapedia.co.ke/api/v2/paypal/order/capture")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = "Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e"
form_data = [['environment', 'sandbox'],['client_id', 'xxx'],['client_secret', 'xxx'],['url', 'https://api.sandbox.paypal.com/v2/checkout/orders/2S71025914161602N/capture']]
request.set_form form_data, 'multipart/form-data'
response = https.request(request)
puts response.read_body
http --ignore-stdin --form --follow --timeout 3600 GET 'https://pesapedia.co.ke/api/v2/paypal/order/capture' \
'environment'='sandbox' \
'client_id'='xxx' \
'client_secret'='xxx' \
'url'='https://api.sandbox.paypal.com/v2/checkout/orders/2S71025914161602N/capture' \
Authorization:'Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e'
wget --no-check-certificate --quiet \
--method GET \
--timeout=0 \
--header 'Authorization: Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e' \
--body-data 'environment=sandbox&client_id=xxx&client_secret=xxx&url=https://api.sandbox.paypal.com/v2/checkout/orders/2S71025914161602N/capture' \
'https://pesapedia.co.ke/api/v2/paypal/order/capture'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment