Wow. Creating a payment externally is not really documented any place. Here’s my step by step guide:
setup our billing address as a graphql object
billingAddress={address1:"1234 Main Street", city:"Any Town", company:"", countryCode:US, firstName:"Bobo", lastName: "Smith", phone:"5095551212",provinceCode:"WA",zip:"12345"}
create a transaction session id
rdata={"credit_card":{"number":"4242424242424242","first_name":"Bobo","last_name":"Smith","month":"1","year":"2024","verification_value":"555"}}
NOTE – this query does NOT validate the credit card. It simply creates a session that belongs to whatever information is submitted, valid or not.
Set objRequest = server.createobject("WinHttp.WinHttpRequest.5.1")
objRequest.open "POST","https://elb.deposit.shopifycs.com/sessions", false
objRequest.setRequestHeader "X-Shopify-Access-Token", ${adminApiToken}
objRequest.setRequestHeader "Content-Type", "application/json"
objRequest.send rdata
the response will look something like this:
{"id":"east-c6b1e88affb51bfe809ad229a52175f5"}
sessionId=response.id
let’s make sure the credit card is valid and is available in the customer’s vault.
gqlRequest="mutation {customerPaymentMethodCreditCardCreate(billingAddress: ${billingAddress}, customerId: "gid://shopify/Customer/1234567890", sessionId: "${sessionId}") { customerPaymentMethod { id revokedReason } userErrors { field message }}}"
t=submitAdminGraphQL(gqlRequest,ct_Graphql) <--------------GRAPHQL REQUEST
parse that response for errors. About the only valid error is “has already been taken”, meaning the card has already been entered into the card vault for that customer. Otherwise, we need nothing from that response if there are no other errors
create the parent transaction. NOTE: the “source”:“external” is important…and completely undocumented
rdata={"transaction":{"currency":"USD","amount":20,"kind":"authorization","source":"external"}}
t=submitAdminApi("POST", "json","orders/"${orderId}"/transactions.json", rdata) <-----------------API REQUEST
We’ll get back something like this:
{
"transaction": {
"id": 5819902296318,
"order_id": 5018385514750,
"kind": "authorization",
"gateway": "manual (shopify_installments)",
"status": "success",
"message": null,
"created_at": "2022-12-06T16:36:10-08:00",
"test": false,
"authorization": null,
"location_id": null,
"user_id": null,
"parent_id": null,
"processed_at": "2022-12-06T16:36:10-08:00",
"device_id": null,
"error_code": null,
"source_name": "6722249",
"receipt": {},
"amount": "20.00",
"currency": "USD",
"admin_graphql_api_id": "gid:\/\/shopify\/OrderTransaction\/5819902296318"
}
}
parentTransactionId=transaction.id
Now, create the payment/sale/capture transaction:
rdata={"transaction":{"currency":"USD","amount":20,"kind":"sale","parentTransactionId":"${parentTransactionId}","source":"external"}}
t=submitAdminApi("POST", "json","orders/"&orderId&"/transactions.json", rdata) <----------API REQUEST
We get something like this back:
{
"transaction": {
"id": 5902144798958,
"order_id": 5027944726766,
"kind": "sale",
"gateway": "shopify_payments",
"status": "success",
"message": null,
"created_at": "2022-12-06T17:02:33-08:00",
"test": true,
"authorization": null,
"location_id": null,
"user_id": null,
"parent_id": null,
"processed_at": "2022-12-06T17:02:33-08:00",
"device_id": null,
"error_code": null,
"source_name": "6771057",
"receipt": {},
"amount": "20.00",
"currency": "USD",
"admin_graphql_api_id": "gid:\/\/shopify\/OrderTransaction\/5902144798958"
}
}
and we’ve successfully created a payment