Prefixing Shopify invoices, passing real orderId

This commit is contained in:
rockstardev
2020-09-13 23:54:15 -05:00
committed by Kukks
parent c39138e3ba
commit 0818abe233
2 changed files with 9 additions and 5 deletions

View File

@@ -28,6 +28,8 @@ namespace BTCPayServer.Services.Shopify
private CancellationTokenSource _Cts;
private readonly CompositeDisposable leases = new CompositeDisposable();
public const string SHOPIFY_ORDER_ID_PREFIX = "shopify-";
public Task StartAsync(CancellationToken cancellationToken)
{
_Cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
@@ -41,8 +43,11 @@ namespace BTCPayServer.Services.Shopify
var storeData = await _storeRepository.FindStore(invoice.StoreId);
var storeBlob = storeData.GetStoreBlob();
if (storeBlob.Shopify?.IntegratedAt.HasValue == true)
if (storeBlob.Shopify?.IntegratedAt.HasValue == true &&
shopifyOrderId.StartsWith(SHOPIFY_ORDER_ID_PREFIX, StringComparison.OrdinalIgnoreCase))
{
shopifyOrderId = shopifyOrderId[SHOPIFY_ORDER_ID_PREFIX.Length..];
var client = createShopifyApiClient(storeBlob.Shopify);
if (!await client.OrderExists(shopifyOrderId))
{

View File

@@ -17,6 +17,7 @@
// extracted from shopify initialized page
const shopify_price = Shopify.checkout.payment_due;
const shopify_currency = Shopify.checkout.currency;
const shopify_order_id = "shopify-" + Shopify.checkout.order_id;
"use strict";
const pageElements = document.querySelector.bind(document),
@@ -79,9 +80,7 @@
pageItems.orderConfirmed && (pageItems.orderConfirmed.style.display = "none"),
pageItems.orderConfirmedDescription && (pageItems.orderConfirmedDescription.style.display = "none");
const orderId = pageItems.orderNumber.innerText.replace("Order #", "");
const url = BTCPAYSERVER_URL + "/invoices" + "?storeId=" + STORE_ID + "&orderId=" + orderId + "&status=complete";
const url = BTCPAYSERVER_URL + "/invoices" + "?storeId=" + STORE_ID + "&orderId=" + shopify_order_id + "&status=complete";
// Check if already paid.
fetch(url, {
@@ -112,7 +111,7 @@
{
price: shopify_price,
currency: shopify_currency,
orderId: orderId
orderId: shopify_order_id
}
)
.then(function (invoice) {