[dbo].[SaveRecurringPaymentInfoForStorage]
create procedure [dbo].[SaveRecurringPaymentInfoForStorage]
@inStorageId int,
@inInstrumentId int,
@inProviderRecurringTransactionId nvarchar(64)
as
set nocount on;
declare @theRowsUpdated int
declare @theCurrentUtcDate datetime = getutcdate()
insert into StoragePaymentTransactionTracking
(
StorageFID,
InstrumentFID,
FirstTransactionID,
FirstTransactionUtcDate,
LastTransactionID,
LastTransactionUtcDate
)
select
StorageFID = @inStorageId,
InstrumentFID = @inInstrumentId,
FirstTransactionID = @inProviderRecurringTransactionId,
FirstTransactionUtcDate = @theCurrentUtcDate,
LastTransactionID = @inProviderRecurringTransactionId,
LastTransactionUtcDate = @theCurrentUtcDate
where not exists(
select top 1 1
from StoragePaymentTransactionTracking
where StorageFID = @inStorageId and
InstrumentFID = @inInstrumentId
)
set @theRowsUpdated = @@rowcount
if( @theRowsUpdated = 0 )
begin
update StoragePaymentTransactionTracking set
LastTransactionID = @inProviderRecurringTransactionId,
LastTransactionUtcDate = @theCurrentUtcDate
where StorageFID = @inStorageId and
InstrumentFID = @inInstrumentId
end
GO
GRANT EXECUTE ON [dbo].[SaveRecurringPaymentInfoForStorage] TO [MssExec]
GO