Card payments
Introduction
The card payments feature allows users to send money using their debit or credit cards through our platform's API. This documentation provides details on how to make card payments via HTTP POST requests and includes code examples in various programming languages.
Sending Money with Card Payments
To send money using card payments, users need to make an HTTP POST request to the specified endpoint with the required parameters.
Endpoint
https://api.mypayd.app/api/v1/payments
Authorization
Users need to include basic authentication credentials in the request headers.
Request Body (Token Object)
The request body should include the necessary parameters for the transaction, such as the amount, recipient's email, location, username, payment method (card), and phone number.
{
"amount": 10,
"email": "johndoe@gmail.com",
"location": "city",
"username": "johndoe",
"payment_method": "card",
"phone": "0712345678"
}
Code Examples
Below are code examples in different programming languages demonstrating how to make card payments using HTTP POST requests.
- Curl
- Go
- Nodejs
- Python
- PHP
curl --location 'https://api.mypayd.app/api/v1/payments' \
--data-raw '{
"amount": 10,
"email": "johndoe@gmail.com",
"location": "city",
"username": "johndoe",
"payment_method": "card",
"phone": "0712345678"
}'
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.mypayd.app/api/v1/payments"
method := "POST"
payload := strings.NewReader(`{
"amount": 10,
"email": "johndoe@gmail.com",
"location": "city",
"username": "johndoe",
"payment_method": "card",
"phone": "0712345678"
}`)
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
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 axios = require('axios');
var data = '{\n "amount": 10,\n "email": "johndoe@gmail.com",\n "location": "city",\n "username": "johndoe",\n "payment_method": "card",\n "phone": "0712345678"\n}';
var config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://api.mypayd.app/api/v1/payments',
headers: { },
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
import requests
url = "https://api.mypayd.app/api/v1/payments"
payload = "{\n \"amount\": 10,\n \"email\": \"johndoe@gmail.com\",\n \"location\": \"city\",\n \"username\": \"johndoe\",\n \"payment_method\": \"card\",\n \"phone\": \"0712345678\"\n}"
headers = {}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://api.mypayd.app/api/v1/payments');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setBody('{\n "amount": 10,\n "email": "johndoe@gmail.com",\n "location": "city",\n "username": "johndoe",\n "payment_method": "card",\n "phone": "0712345678"\n}');
try {
$response = $request->send();
if ($response->getStatus() == 200) {
echo $response->getBody();
}
else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
$response->getReasonPhrase();
}
}
catch(HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
Example of a successful response
{
"status": 1,
"status_code": "200",
"success": true,
"transaction_type": "bill payment",
"message": "Payment processed successfully",
"checkout_url": "https://example.com/checkout",
"transaction_reference": "trans123",
"merchant_reference": "trans123",
"channel": "card",
"payment_gateway": "paystack"
}
Conclusion
The card payments feature provides a convenient way for users to send money securely using their debit or credit cards. By following the instructions outlined in this documentation, users can easily integrate card payments into their applications or services.