import os
import requests
url = "https://api.stripe.com/v1/invoices/in_1234567890/pay"
headers = {
"Authorization": f"Bearer {os.environ['STRIPE_SECRET_KEY']}",
"Stripe-Version": "2023-10-16"
}
response = requests.post(url, headers=headers)
response.raise_for_status()
print(response.json())
import os
import httpx
url = "https://api.stripe.com/v1/invoices/in_1234567890/pay"
headers = {
"Authorization": f"Bearer {os.environ['STRIPE_SECRET_KEY']}",
"Stripe-Version": "2023-10-16"
}
with httpx.Client() as client:
response = client.post(url, headers=headers)
response.raise_for_status()
print(response.json())
import fetch from 'node-fetch';
import process from 'process';
const url = new URL('https://api.stripe.com/v1/invoices/in_1234567890/pay');
const headers = {
'Authorization': `Bearer ${process.env.STRIPE_SECRET_KEY}`,
'Stripe-Version': '2023-10-16'
};
try {
const response = await fetch(url, { method: 'POST', headers });
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
const data = await response.json();
console.log(data);
} catch (error) {
console.error('Error:', error);
}
import axios from 'axios';
import process from 'process';
const url = 'https://api.stripe.com/v1/invoices/in_1234567890/pay';
const headers = {
'Authorization': `Bearer ${process.env.STRIPE_SECRET_KEY}`,
'Stripe-Version': '2023-10-16'
};
try {
const response = await axios.post(url, null, { headers });
console.log(response.data);
} catch (error) {
if (error.response) {
console.error('Error:', error.response.status, error.response.data);
} else {
console.error('Error:', error.message);
}
}
package main
import (
"fmt"
"log"
"net/http"
"os"
)
func main() {
url := "https://api.stripe.com/v1/invoices/in_1234567890/pay"
client := &http.Client{}
req, err := http.NewRequest("POST", url, nil)
if err != nil {
log.Fatal(err)
}
req.Header.Set("Authorization", "Bearer "+os.Getenv("STRIPE_SECRET_KEY"))
req.Header.Set("Stripe-Version", "2023-10-16")
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
log.Fatalf("Unexpected status code: %d", resp.StatusCode)
}
// Assuming JSON response
// var result map[string]interface{}
// json.NewDecoder(resp.Body).Decode(&result)
// fmt.Println(result)
fmt.Println("Request successful")
}
<?php
$url = 'https://api.stripe.com/v1/invoices/in_1234567890/pay';
$headers = [
'Authorization: Bearer ' . getenv('STRIPE_SECRET_KEY'),
'Stripe-Version: 2023-10-16'
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
if (curl_errno($ch)) {
die('Error: ' . curl_error($ch));
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode !== 200) {
die("HTTP error: $httpCode");
}
$json = json_decode($response, true);
print_r($json);
curl_close($ch);
require 'net/http'
require 'json'
require 'uri'
url = URI.parse('https://api.stripe.com/v1/invoices/in_1234567890/pay')
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url.path)
request['Authorization'] = "Bearer #{ENV['STRIPE_SECRET_KEY']}"
request['Stripe-Version'] = '2023-10-16'
response = http.request(request)
unless response.is_a?(Net::HTTPSuccess)
raise "HTTP error: #{response.code}"
end
puts JSON.parse(response.body)
import Foundation
let url = URL(string: "https://api.stripe.com/v1/invoices/in_1234567890/pay")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("Bearer \(ProcessInfo.processInfo.environment["STRIPE_SECRET_KEY"] ?? "")", forHTTPHeaderField: "Authorization")
request.setValue("2023-10-16", forHTTPHeaderField: "Stripe-Version")
let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let error = error {
print("Error: \(error)")
return
}
guard let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200 else {
print("HTTP error: \((response as? HTTPURLResponse)?.statusCode ?? 0)")
return
}
if let data = data, let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any] {
print(json)
}
}
task.resume()
// Run in a context that supports async (e.g., Swift Concurrency)
RunLoop.main.run()
use std::env;
use reqwest;
use serde_json::Value;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let url = "https://api.stripe.com/v1/invoices/in_1234567890/pay";
let stripe_key = env::var("STRIPE_SECRET_KEY")?;
let client = reqwest::Client::new();
let response = client
.post(url)
.header("Authorization", format!("Bearer {}", stripe_key))
.header("Stripe-Version", "2023-10-16")
.send()
.await?;
if !response.status().is_success() {
return Err(format!("HTTP error: {}", response.status()).into());
}
let json: Value = response.json().await?;
println!("{:?}", json);
Ok(())
}
using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
var url = "https://api.stripe.com/v1/invoices/in_1234567890/pay";
var stripeKey = Environment.GetEnvironmentVariable("STRIPE_SECRET_KEY");
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {stripeKey}");
client.DefaultRequestHeaders.Add("Stripe-Version", "2023-10-16");
var response = await client.PostAsync(url, null);
if (!response.IsSuccessStatusCode)
{
throw new Exception($"HTTP error: {response.StatusCode}");
}
var json = await response.Content.ReadAsStringAsync();
Console.WriteLine(json);
}
}