Skip to content

Instantly share code, notes, and snippets.

@paulwababu
Last active December 4, 2022 15:56
Show Gist options
  • Save paulwababu/49d99c12c3b1c8665b986431a5b3857c to your computer and use it in GitHub Desktop.
Save paulwababu/49d99c12c3b1c8665b986431a5b3857c to your computer and use it in GitHub Desktop.
Create Order PESAPEDIA . Paypal on PESAPEDIA accepts only USD, TO CONVERT USE. https://pesapedia.co.ke/musk/exchangerate?to=USD&from=KES&amount=100
var client = new RestClient("https://pesapedia.co.ke/api/v2/paypal/order/create");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
request.AddHeader("Authorization", "Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e");
request.AlwaysMultipartFormData = true;
request.AddParameter("client_id", "xxx");
request.AddParameter("client_secret", "xxx");
request.AddParameter("environment", "sandbox");
request.AddParameter("notify_url", "https://pesapedia.co.ke/api/v2/paypal/cancel/callback");
request.AddParameter("return_url", "https://pesapedia.co.ke/api/v2/paypal/return/callback");
request.AddParameter("cancel_url", "https://pesapedia.co.ke/api/v2/paypal/return/callback");
request.AddParameter("brand_name", "PESAPEDIA SANDBOX");
request.AddParameter("reference_id", "294375635");
request.AddParameter("description", "African Art and Collectibles");
request.AddParameter("custom_id", "CUST-AfricanFashion");
request.AddParameter("soft_descriptor", "AfricanFashions");
request.AddParameter("amount_in_dollars", "100");
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
curl --location --request GET 'https://pesapedia.co.ke/api/v2/paypal/order/create' \
--header 'Authorization: Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e' \
--form 'client_id="xxx"' \
--form 'client_secret="xxx"' \
--form 'environment="sandbox"' \
--form 'notify_url="https://pesapedia.co.ke/api/v2/paypal/cancel/callback"' \
--form 'return_url="https://pesapedia.co.ke/api/v2/paypal/return/callback"' \
--form 'cancel_url="https://pesapedia.co.ke/api/v2/paypal/return/callback"' \
--form 'brand_name="PESAPEDIA SANDBOX"' \
--form 'reference_id="294375635"' \
--form 'description="African Art and Collectibles"' \
--form 'custom_id="CUST-AfricanFashion"' \
--form 'soft_descriptor="AfricanFashions"' \
--form 'amount_in_dollars="100"'
var headers = {
'Authorization': 'Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e'
};
var request = http.MultipartRequest('GET', Uri.parse('https://pesapedia.co.ke/api/v2/paypal/order/create'));
request.fields.addAll({
'client_id': 'xxx',
'client_secret': 'xxx',
'environment': 'sandbox',
'notify_url': 'https://pesapedia.co.ke/api/v2/paypal/cancel/callback',
'return_url': 'https://pesapedia.co.ke/api/v2/paypal/return/callback',
'cancel_url': 'https://pesapedia.co.ke/api/v2/paypal/return/callback',
'brand_name': 'PESAPEDIA SANDBOX',
'reference_id': '294375635',
'description': 'African Art and Collectibles',
'custom_id': 'CUST-AfricanFashion',
'soft_descriptor': 'AfricanFashions',
'amount_in_dollars': '100'
});
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/create"
method := "GET"
payload := &bytes.Buffer{}
writer := multipart.NewWriter(payload)
_ = writer.WriteField("client_id", "xxx")
_ = writer.WriteField("client_secret", "xxx")
_ = writer.WriteField("environment", "sandbox")
_ = writer.WriteField("notify_url", "https://pesapedia.co.ke/api/v2/paypal/cancel/callback")
_ = writer.WriteField("return_url", "https://pesapedia.co.ke/api/v2/paypal/return/callback")
_ = writer.WriteField("cancel_url", "https://pesapedia.co.ke/api/v2/paypal/return/callback")
_ = writer.WriteField("brand_name", "PESAPEDIA SANDBOX")
_ = writer.WriteField("reference_id", "294375635")
_ = writer.WriteField("description", "African Art and Collectibles")
_ = writer.WriteField("custom_id", "CUST-AfricanFashion")
_ = writer.WriteField("soft_descriptor", "AfricanFashions")
_ = writer.WriteField("amount_in_dollars", "100")
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("client_id", "xxx");
formdata.append("client_secret", "xxx");
formdata.append("environment", "sandbox");
formdata.append("notify_url", "https://pesapedia.co.ke/api/v2/paypal/cancel/callback");
formdata.append("return_url", "https://pesapedia.co.ke/api/v2/paypal/return/callback");
formdata.append("cancel_url", "https://pesapedia.co.ke/api/v2/paypal/return/callback");
formdata.append("brand_name", "PESAPEDIA SANDBOX");
formdata.append("reference_id", "294375635");
formdata.append("description", "African Art and Collectibles");
formdata.append("custom_id", "CUST-AfricanFashion");
formdata.append("soft_descriptor", "AfricanFashions");
formdata.append("amount_in_dollars", "100");
var requestOptions = {
method: 'GET',
headers: myHeaders,
body: formdata,
redirect: 'follow'
};
fetch("https://pesapedia.co.ke/api/v2/paypal/order/create", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
var form = new FormData();
form.append("client_id", "xxx");
form.append("client_secret", "xxx");
form.append("environment", "sandbox");
form.append("notify_url", "https://pesapedia.co.ke/api/v2/paypal/cancel/callback");
form.append("return_url", "https://pesapedia.co.ke/api/v2/paypal/return/callback");
form.append("cancel_url", "https://pesapedia.co.ke/api/v2/paypal/return/callback");
form.append("brand_name", "PESAPEDIA SANDBOX");
form.append("reference_id", "294375635");
form.append("description", "African Art and Collectibles");
form.append("custom_id", "CUST-AfricanFashion");
form.append("soft_descriptor", "AfricanFashions");
form.append("amount_in_dollars", "100");
var settings = {
"url": "https://pesapedia.co.ke/api/v2/paypal/order/create",
"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("client_id", "xxx");
data.append("client_secret", "xxx");
data.append("environment", "sandbox");
data.append("notify_url", "https://pesapedia.co.ke/api/v2/paypal/cancel/callback");
data.append("return_url", "https://pesapedia.co.ke/api/v2/paypal/return/callback");
data.append("cancel_url", "https://pesapedia.co.ke/api/v2/paypal/return/callback");
data.append("brand_name", "PESAPEDIA SANDBOX");
data.append("reference_id", "294375635");
data.append("description", "African Art and Collectibles");
data.append("custom_id", "CUST-AfricanFashion");
data.append("soft_descriptor", "AfricanFashions");
data.append("amount_in_dollars", "100");
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/create");
xhr.setRequestHeader("Authorization", "Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e");
xhr.send(data);
var axios = require('axios');
var FormData = require('form-data');
var data = new FormData();
data.append('client_id', 'xxx');
data.append('client_secret', 'xxx');
data.append('environment', 'sandbox');
data.append('notify_url', 'https://pesapedia.co.ke/api/v2/paypal/cancel/callback');
data.append('return_url', 'https://pesapedia.co.ke/api/v2/paypal/return/callback');
data.append('cancel_url', 'https://pesapedia.co.ke/api/v2/paypal/return/callback');
data.append('brand_name', 'PESAPEDIA SANDBOX');
data.append('reference_id', '294375635');
data.append('description', 'African Art and Collectibles');
data.append('custom_id', 'CUST-AfricanFashion');
data.append('soft_descriptor', 'AfricanFashions');
data.append('amount_in_dollars', '100');
var config = {
method: 'get',
url: 'https://pesapedia.co.ke/api/v2/paypal/order/create',
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/create',
'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=\"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=\"environment\"\r\n\r\nsandbox\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"notify_url\"\r\n\r\nhttps://pesapedia.co.ke/api/v2/paypal/cancel/callback\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"return_url\"\r\n\r\nhttps://pesapedia.co.ke/api/v2/paypal/return/callback\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"cancel_url\"\r\n\r\nhttps://pesapedia.co.ke/api/v2/paypal/return/callback\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"brand_name\"\r\n\r\nPESAPEDIA SANDBOX\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"reference_id\"\r\n\r\n294375635\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"description\"\r\n\r\nAfrican Art and Collectibles\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"custom_id\"\r\n\r\nCUST-AfricanFashion\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"soft_descriptor\"\r\n\r\nAfricanFashions\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"amount_in_dollars\"\r\n\r\n100\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/create',
'headers': {
'Authorization': 'Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e'
},
formData: {
'client_id': 'xxx',
'client_secret': 'xxx',
'environment': 'sandbox',
'notify_url': 'https://pesapedia.co.ke/api/v2/paypal/cancel/callback',
'return_url': 'https://pesapedia.co.ke/api/v2/paypal/return/callback',
'cancel_url': 'https://pesapedia.co.ke/api/v2/paypal/return/callback',
'brand_name': 'PESAPEDIA SANDBOX',
'reference_id': '294375635',
'description': 'African Art and Collectibles',
'custom_id': 'CUST-AfricanFashion',
'soft_descriptor': 'AfricanFashions',
'amount_in_dollars': '100'
}
};
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/create')
.headers({
'Authorization': 'Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e'
})
.field('client_id', 'xxx')
.field('client_secret', 'xxx')
.field('environment', 'sandbox')
.field('notify_url', 'https://pesapedia.co.ke/api/v2/paypal/cancel/callback')
.field('return_url', 'https://pesapedia.co.ke/api/v2/paypal/return/callback')
.field('cancel_url', 'https://pesapedia.co.ke/api/v2/paypal/return/callback')
.field('brand_name', 'PESAPEDIA SANDBOX')
.field('reference_id', '294375635')
.field('description', 'African Art and Collectibles')
.field('custom_id', 'CUST-AfricanFashion')
.field('soft_descriptor', 'AfricanFashions')
.field('amount_in_dollars', '100')
.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/create',
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('client_id' => 'xxx,'client_secret' => 'xxx','environment' => 'sandbox','notify_url' => 'https://pesapedia.co.ke/api/v2/paypal/cancel/callback','return_url' => 'https://pesapedia.co.ke/api/v2/paypal/return/callback','cancel_url' => 'https://pesapedia.co.ke/api/v2/paypal/return/callback','brand_name' => 'PESAPEDIA SANDBOX','reference_id' => '294375635','description' => 'African Art and Collectibles','custom_id' => 'CUST-AfricanFashion','soft_descriptor' => 'AfricanFashions','amount_in_dollars' => '100'),
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/create"
payload={'client_id': 'your paypal client id',
'client_secret': 'your paypal client secret',
'environment': 'sandbox', #for production, change to production
'notify_url': 'https://pesapedia.co.ke/api/v2/paypal/cancel/callback',
'return_url': 'https://pesapedia.co.ke/api/v2/paypal/return/callback',
'cancel_url': 'https://pesapedia.co.ke/api/v2/paypal/return/callback',
'brand_name': 'PESAPEDIA SANDBOX',
'reference_id': '294375635',
'description': 'African Art and Collectibles',
'custom_id': 'CUST-AfricanFashion',
'soft_descriptor': 'AfricanFashions',
'amount_in_dollars': '100'}
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(
'client_id' = 'xxx',
'client_secret' = 'xxx',
'environment' = 'sandbox',
'notify_url' = 'https://pesapedia.co.ke/api/v2/paypal/cancel/callback',
'return_url' = 'https://pesapedia.co.ke/api/v2/paypal/return/callback',
'cancel_url' = 'https://pesapedia.co.ke/api/v2/paypal/return/callback',
'brand_name' = 'PESAPEDIA SANDBOX',
'reference_id' = '294375635',
'description' = 'African Art and Collectibles',
'custom_id' = 'CUST-AfricanFashion',
'soft_descriptor' = 'AfricanFashions',
'amount_in_dollars' = '100'
)
res <- VERB("GET", url = "https://pesapedia.co.ke/api/v2/paypal/order/create", body = body, add_headers(headers), encode = 'multipart')
cat(content(res, 'text'))
library(RCurl)
headers = c(
"Authorization" = "Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e"
)
params = c(
"client_id" = "xxx",
"client_secret" = "xxx",
"environment" = "sandbox",
"notify_url" = "https://pesapedia.co.ke/api/v2/paypal/cancel/callback",
"return_url" = "https://pesapedia.co.ke/api/v2/paypal/return/callback",
"cancel_url" = "https://pesapedia.co.ke/api/v2/paypal/return/callback",
"brand_name" = "PESAPEDIA SANDBOX",
"reference_id" = "294375635",
"description" = "African Art and Collectibles",
"custom_id" = "CUST-AfricanFashion",
"soft_descriptor" = "AfricanFashions",
"amount_in_dollars" = "100"
)
res <- getURL("https://pesapedia.co.ke/api/v2/paypal/order/create", .opts=list(httpheader = headers, followlocation = TRUE))
cat(res)
require "uri"
require "net/http"
url = URI("https://pesapedia.co.ke/api/v2/paypal/order/create")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = "Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e"
form_data = [['client_id', 'xxx'],['client_secret', 'xxx'],['environment', 'sandbox'],['notify_url', 'https://pesapedia.co.ke/api/v2/paypal/cancel/callback'],['return_url', 'https://pesapedia.co.ke/api/v2/paypal/return/callback'],['cancel_url', 'https://pesapedia.co.ke/api/v2/paypal/return/callback'],['brand_name', 'PESAPEDIA SANDBOX'],['reference_id', '294375635'],['description', 'African Art and Collectibles'],['custom_id', 'CUST-AfricanFashion'],['soft_descriptor', 'AfricanFashions'],['amount_in_dollars', '100']]
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/create' \
'client_id'='xxx' \
'client_secret'='xxx' \
'environment'='sandbox' \
'notify_url'='https://pesapedia.co.ke/api/v2/paypal/cancel/callback' \
'return_url'='https://pesapedia.co.ke/api/v2/paypal/return/callback' \
'cancel_url'='https://pesapedia.co.ke/api/v2/paypal/return/callback' \
'brand_name'='PESAPEDIA SANDBOX' \
'reference_id'='294375635' \
'description'='African Art and Collectibles' \
'custom_id'='CUST-AfricanFashion' \
'soft_descriptor'='AfricanFashions' \
'amount_in_dollars'='100' \
Authorization:'Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e'
wget --no-check-certificate --quiet \
--method GET \
--timeout=0 \
--header 'Authorization: Token fcf3081d09f4c8e37a74f1f528bc37c3ca93091e' \
--body-data 'client_id=xxx&client_secret=xxx&environment=sandbox&notify_url=https://pesapedia.co.ke/api/v2/paypal/cancel/callback&return_url=https://pesapedia.co.ke/api/v2/paypal/return/callback&cancel_url=https://pesapedia.co.ke/api/v2/paypal/return/callback&brand_name=PESAPEDIA SANDBOX&reference_id=294375635&description=African Art and Collectibles&custom_id=CUST-AfricanFashion&soft_descriptor=AfricanFashions&amount_in_dollars=100' \
'https://pesapedia.co.ke/api/v2/paypal/order/create'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment