From 15c7bed4de443d11c73fb418f4ce23725c193cb8 Mon Sep 17 00:00:00 2001 From: Ashelyn Dawn Date: Fri, 27 Nov 2020 22:51:37 -0700 Subject: [PATCH] Save Stripe Receipt number --- db/mappings/order.js | 2 +- db/models/order.js | 3 ++- db/sql/1-tables.sql | 3 ++- db/sql/2-views.sql | 2 +- db/sql/3-functions.sql | 8 +++++--- pages/store/checkout/complete.js | 2 +- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/db/mappings/order.js b/db/mappings/order.js index b6504eb..a11def7 100644 --- a/db/mappings/order.js +++ b/db/mappings/order.js @@ -75,7 +75,7 @@ module.exports = [{ mapId: 'paymentStripeMap', idProperty: 'payment_intent_id', properties: [ - 'reciept_email' + 'receipt_email' ] },{ mapId: 'deliveryMap', diff --git a/db/models/order.js b/db/models/order.js index 9193bff..70075d9 100644 --- a/db/models/order.js +++ b/db/models/order.js @@ -247,7 +247,8 @@ order.addPayment = async function(transaction, paymentIntent){ transaction.uuid, paymentIntent.amount_received, paymentIntent.id, - paymentIntent.receipt_email + paymentIntent.receipt_email, + paymentIntent.charges.data[0].receipt_number ], returnType: 'order', single: true diff --git a/db/sql/1-tables.sql b/db/sql/1-tables.sql index 0f20172..2eabe9a 100644 --- a/db/sql/1-tables.sql +++ b/db/sql/1-tables.sql @@ -215,7 +215,8 @@ create table sos."payment_stripe" ( foreign key (payment_uuid, payment_type) references sos."payment" (payment_uuid, payment_type), stripe_payment_intent_id text unique not null, - stripe_reciept_email citext not null + stripe_receipt_email citext not null, + stripe_receipt_number text NULL ); create table sos."shipment" ( diff --git a/db/sql/2-views.sql b/db/sql/2-views.sql index 02e1846..36626fa 100644 --- a/db/sql/2-views.sql +++ b/db/sql/2-views.sql @@ -81,7 +81,7 @@ create or replace view sos.v_payment as select payment.*, payment_stripe.stripe_payment_intent_id, - payment_stripe.stripe_reciept_email + payment_stripe.stripe_receipt_email from sos."payment" left join sos."payment_ks_reward" on payment_ks_reward.payment_uuid = payment.payment_uuid and payment_ks_reward.payment_type = payment.payment_type left join sos."payment_stripe" on payment_stripe.payment_uuid = payment.payment_uuid and payment_stripe.payment_type = payment.payment_type; diff --git a/db/sql/3-functions.sql b/db/sql/3-functions.sql index 201533e..42d77b5 100644 --- a/db/sql/3-functions.sql +++ b/db/sql/3-functions.sql @@ -747,7 +747,7 @@ begin where "transaction".transaction_uuid = _transaction_uuid; end; $function$; -create or replace function sos.add_stripe_payment_to_transaction(_transaction_uuid uuid, _payment_value_cents integer, _stripe_intent_id text, _stripe_reciept_email citext) +create or replace function sos.add_stripe_payment_to_transaction(_transaction_uuid uuid, _payment_value_cents integer, _stripe_intent_id text, _stripe_receipt_email citext, _stripe_receipt_number text) returns setof sos.v_order language plpgsql as $function$ @@ -779,12 +779,14 @@ begin payment_uuid, payment_type, stripe_payment_intent_id, - stripe_reciept_email + stripe_receipt_email, + stripe_receipt_number ) values ( _payment_uuid, 'stripe', _stripe_intent_id, - _stripe_reciept_email + _stripe_receipt_email, + _stripe_receipt_number ); select diff --git a/pages/store/checkout/complete.js b/pages/store/checkout/complete.js index 8e99e59..f5ba158 100644 --- a/pages/store/checkout/complete.js +++ b/pages/store/checkout/complete.js @@ -19,7 +19,7 @@ export default function CheckoutComplete({order}){ const stripePayment = latestTransaction.payments.find(p => p.stripe !== null) if(stripePayment) - email = stripePayment.stripe.reciept_email + email = stripePayment.stripe.receipt_email return ( <>