import os
import requests
response = requests.get(
"https://api.stripe.com/v1/payment_intents/pi_3O9xYx2eZvKYlo2C0lq4XyqL",
headers={"Authorization": f"Bearer {os.environ['STRIPE_SECRET_KEY']}"}
)
response.raise_for_status()
print(response.json())
import os
import httpx
with httpx.Client() as client:
response = client.get(
"https://api.stripe.com/v1/payment_intents/pi_3O9xYx2eZvKYlo2C0lq4XyqL",
headers={"Authorization": f"Bearer {os.environ['STRIPE_SECRET_KEY']}"}
)
response.raise_for_status()
print(response.json())
import fetch from 'node-fetch';
const response = await fetch(
'https://api.stripe.com/v1/payment_intents/pi_3O9xYx2eZvKYlo2C0lq4XyqL',
{
method: 'GET',
headers: {
'Authorization': `Bearer ${process.env.STRIPE_SECRET_KEY}`
}
}
);
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
const data = await response.json();
console.log(data);
import axios from 'axios';
const response = await axios.get(
'https://api.stripe.com/v1/payment_intents/pi_3O9xYx2eZvKYlo2C0lq4XyqL',
{
headers: {
'Authorization': `Bearer ${process.env.STRIPE_SECRET_KEY}`
}
}
);
console.log(response.data);
package main
import (
"fmt"
"net/http"
"os"
)
func main() {
req, err := http.NewRequest(
"GET",
"https://api.stripe.com/v1/payment_intents/pi_3O9xYx2eZvKYlo2C0lq4XyqL",
nil,
)
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+os.Getenv("STRIPE_SECRET_KEY"))
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
panic(fmt.Sprintf("HTTP error! status: %s", resp.Status))
}
// Handle response body as needed
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.stripe.com/v1/payment_intents/pi_3O9xYx2eZvKYlo2C0lq4XyqL');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . getenv('STRIPE_SECRET_KEY')
]);
$response = curl_exec($ch);
if (curl_errno($ch)) {
throw new Exception(curl_error($ch));
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode !== 200) {
throw new Exception("HTTP error! status: $httpCode");
}
$data = json_decode($response, true);
print_r($data);
curl_close($ch);
require 'net/http'
require 'json'
uri = URI('https://api.stripe.com/v1/payment_intents/pi_3O9xYx2eZvKYlo2C0lq4XyqL')
req = Net::HTTP::Get.new(uri)
req['Authorization'] = "Bearer #{ENV['STRIPE_SECRET_KEY']}"
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(req)
end
unless res.is_a?(Net::HTTPSuccess)
raise "HTTP error! status: #{res.code}"
end
puts JSON.parse(res.body)
import Foundation
let url = URL(string: "https://api.stripe.com/v1/payment_intents/pi_3O9xYx2eZvKYlo2C0lq4XyqL")!
var request = URLRequest(url: url)
request.httpMethod = "GET"
request.setValue("Bearer \(ProcessInfo.processInfo.environment["STRIPE_SECRET_KEY"] ?? "")", forHTTPHeaderField: "Authorization")
let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let error = error {
fatalError("Error: \(error)")
}
guard let httpResponse = response as? HTTPURLResponse,
(200...299).contains(httpResponse.statusCode) else {
fatalError("HTTP error! status: \((response as? HTTPURLResponse)?.statusCode ?? 0)")
}
if let data = data,
let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any] {
print(json)
}
}
task.resume()
RunLoop.main.run()
use reqwest;
use std::env;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = reqwest::Client::new();
let url = "https://api.stripe.com/v1/payment_intents/pi_3O9xYx2eZvKYlo2C0lq4XyqL";
let api_key = env::var("STRIPE_SECRET_KEY")?;
let response = client
.get(url)
.header("Authorization", format!("Bearer {}", api_key))
.send()
.await?;
if !response.status().is_success() {
return Err(format!("HTTP error! status: {}", response.status()).into());
}
let body = response.json::<serde_json::Value>().await?;
println!("{:#?}", body);
Ok(())
}
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
var client = new HttpClient();
var url = "https://api.stripe.com/v1/payment_intents/pi_3O9xYx2eZvKYlo2C0lq4XyqL";
var apiKey = Environment.GetEnvironmentVariable("STRIPE_SECRET_KEY");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
var response = await client.GetAsync(url);
if (!response.IsSuccessStatusCode)
{
throw new Exception($"HTTP error! status: {response.StatusCode}");
}
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
}
}