CARVIEW |
Select Language
HTTP/2 200
date: Wed, 23 Jul 2025 22:02:28 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
etag: W/"82c8ed3d9e9d868af25ec6e22c40e968"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=9lE4T8XwqBUJU8xfHaDMlNQtFaw0rYIMpOalrFhm%2Baq82JlWL4tk4Ds3FKzH4m58LVFgzz%2B8hVre1TcroI3sxq5euEQetB5pSn7wyHR2leReGXluiy1PnYOKCzqlXqFmWbKn7u%2BbZ1dU9cMowPuDYOGAp6i6lKHRFDh38ICGnj9QcaWpq3xBTXqQy0pF2T8RyuHkQne91GigDKgDRUPqmSI4AOLICzSIEYc%2BBpiZmPvz4A7QEOL6MGWbL7oE8LoD99afLTXGIK7F92tLnxeBJg%3D%3D--%2F3zC5%2BuqgovRxmSt--XR0sRId6%2BhDxp2%2Bw9xQjZw%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.258161498.1753308148; Path=/; Domain=github.com; Expires=Thu, 23 Jul 2026 22:02:28 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Thu, 23 Jul 2026 22:02:28 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: B2FA:3B93B0:111BA58:146D786:68815BF4
Migration to StripeClient and services in 7.33.0 · stripe/stripe-php Wiki · GitHub
Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 876
Migration to StripeClient and services in 7.33.0
Ramya Rao edited this page Apr 8, 2025
·
7 revisions
Starting with 7.33.0 of the library, we released a new StripeClient
class which lets you interact with the API without using static methods or having to retrieve a resource before deleting it for example.
While there are no plans yet to completely remove the previous resource-based call pattern, it will be deprecated soon and new API endpoints will be supported only in the new pattern. We strongly recommend migrating to the new service-based pattern as you begin to use new APIs. This will help you avoid mixing the two patterns in your integration, which can lead to confusion as you maintain your code.
In the past, your code would look like this
<?php
// Initialize the API key
\Stripe\Stripe::setApiKey('sk_test_xxx');
// Set a global API version
\Stripe\Stripe::setApiVersion('2022-08-01');
// Retrieve the customer and then delete it
$customer = \Stripe\Customer::retrieve('cus_xxx');
$customer->delete();
// Create a Coupon
$coupon = \Stripe\Coupon::create([
'percent_off' => 25,
'duration' => 'repeating',
'duration_in_months' => 3,
]);
// Retrieve and confirm a PaymentIntent
$paymentIntent = \Stripe\PaymentIntent::retrieve('pi_123');
$paymentIntent->confirm([
'payment_method' => 'pm_card_visa'
];
// Create a Checkout Session
$checkoutSession = \Stripe\Checkout\Session::create([
'success_url' => 'https://www.example.com/success',
'cancel_url' => 'https://www.example.com/failure',
'payment_method_types' => ['card'],
'line_items' => [
[
'price' => 'price_ABCDE',
'quantity' => 2,
],
],
]);
// Retrieve a Checkout Session and expand line_items
// Note the first parameter is now an array with id as a key to pass the resource id which was hard to figure out
$checkoutSession = \Stripe\Checkout\Session::retrieve([
'id' => 'cs_test_123',
'expand' => ['line_items'],
]);
Instead, with the new client/services infrastructure, you can do this:
<?php
// Initialize a client with just the API key
$stripe = new \Stripe\StripeClient('sk_test_xxxx');
// Alternatively initialize a client with the API key and API version
$stripe = new \Stripe\StripeClient([
'api_key' => 'sk_test_xxxx',
'stripe_version' => '2022-08-01',
]);
// Create a coupon
$coupon = $stripe->coupons->create([
'percent_off' => 25,
'duration' => 'repeating',
'duration_in_months' => 3,
]);
// Confirm a PaymentIntent
$paymentIntent = $stripe->paymentIntents->confirm(
'pi_1DeQ7b2eZvKYlo2C5FUypnEA',
['payment_method' => 'pm_card_visa']
);
// Create a Checkout Session
$checkoutSession = $stripe->checkout->sessions->create([
'success_url' => 'https://example.com/success',
'cancel_url' => 'https://example.com/cancel',
'payment_method_types' => ['card'],
'line_items' => [
[
'price' => 'price_ABCDE',
'quantity' => 2,
],
],
]);
// Retrieve a Checkout Session and expand line_items
$checkoutSession = $stripe->checkout->sessions->retrieve(
'cs_test_123',
[
'expand' => ['line_items'],
]
);
Clone this wiki locally
You can’t perform that action at this time.