Trigger payment method re-collection email
Asks Shopify to email the signed-in customer a secure link to update the payment method that the subscription uses now. Use it when the card is expiring or was declined. The customer enters the new card on a Shopify-hosted page, so card details never pass through your page or Appstle. The call takes no email content. Shopify sends its Customer payment method update request notification, which the merchant can edit in the Shopify admin under Settings → Notifications. To move the subscription to a payment method the customer has already saved, use Set existing Shopify payment method on contract instead, and list the saved ones with Get current customer’s saved Shopify payment methods.
What the call returns:
200with an empty body means Shopify accepted the request to send the email. It doesn’t mean that the customer received it or updated the card400means nothing was sent. The reason is intitle: a contract that doesn’t belong to the signed-in customer returnserrorKeyinvalidContract, a gift subscription returnserrorKeygiftBuyerReadOnlybecause the buyer can’t change it from the storefront, and an email that Shopify refuses to send returns atitlethat starts withUserGeneratedError:followed by Shopify’s reason401means the request didn’t come through the App Proxy, or no customer is signed in
Shop Pay:
Don’t offer this email for a subscription paid with Shop Pay, where the contract’s customerPaymentMethod.instrument.__typename is CustomerShopPayAgreement. Read it with Get raw Shopify subscription contract (external view). The customer updates that card in their Shop Pay account (Manage your Shop Pay subscriptions).
Important Notes:
- Each call asks Shopify for another email. Appstle doesn’t deduplicate the calls, so send one for each customer request
- When the subscription’s last order failed, Appstle can retry it soon after the customer saves the new card, when the store has Retry as soon as the customer updates their payment method turned on and the subscription is active
- Appstle doesn’t confirm the change. To see which card the subscription bills after the customer uses the link, read
customerPaymentMethodwith Get raw Shopify subscription contract (external view). Shopify can replace the card inside the same payment method, so compare the card’slastDigitsand expiry, not only theid
Authentication: Requires a signed-in customer. Call it through Shopify’s App Proxy on the store’s domain: the proxy signs the request and attaches the customer, so you send no API key.
curl --request PUT \
--url https://www.myshop.com/apps/subscriptions/cp/api/subscription-contracts-update-payment-methodimport requests
url = "https://www.myshop.com/apps/subscriptions/cp/api/subscription-contracts-update-payment-method"
response = requests.put(url)
print(response.text)const options = {method: 'PUT'};
fetch('https://www.myshop.com/apps/subscriptions/cp/api/subscription-contracts-update-payment-method', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));const url = 'https://www.myshop.com/apps/subscriptions/cp/api/subscription-contracts-update-payment-method';
const options = {method: 'PUT'};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://www.myshop.com/apps/subscriptions/cp/api/subscription-contracts-update-payment-method",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://www.myshop.com/apps/subscriptions/cp/api/subscription-contracts-update-payment-method"
req, _ := http.NewRequest("PUT", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}require 'uri'
require 'net/http'
url = URI("https://www.myshop.com/apps/subscriptions/cp/api/subscription-contracts-update-payment-method")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
response = http.request(request)
puts response.read_body{
"errorKey": "invalidContract",
"message": "Contract does not exist",
"params": "",
"status": 400,
"title": "Contract does not exist",
"type": "https://appstle.com/problem/problem-with-message"
}curl --request PUT \
--url https://www.myshop.com/apps/subscriptions/cp/api/subscription-contracts-update-payment-methodimport requests
url = "https://www.myshop.com/apps/subscriptions/cp/api/subscription-contracts-update-payment-method"
response = requests.put(url)
print(response.text)const options = {method: 'PUT'};
fetch('https://www.myshop.com/apps/subscriptions/cp/api/subscription-contracts-update-payment-method', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));const url = 'https://www.myshop.com/apps/subscriptions/cp/api/subscription-contracts-update-payment-method';
const options = {method: 'PUT'};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://www.myshop.com/apps/subscriptions/cp/api/subscription-contracts-update-payment-method",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://www.myshop.com/apps/subscriptions/cp/api/subscription-contracts-update-payment-method"
req, _ := http.NewRequest("PUT", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}require 'uri'
require 'net/http'
url = URI("https://www.myshop.com/apps/subscriptions/cp/api/subscription-contracts-update-payment-method")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
response = http.request(request)
puts response.read_body{
"errorKey": "invalidContract",
"message": "Contract does not exist",
"params": "",
"status": 400,
"title": "Contract does not exist",
"type": "https://appstle.com/problem/problem-with-message"
}