USP_RECORDOPERATION_MERCHANTACCOUNTMARKDEFAULTAUTHORIZATIONACCOUNT

Executes the "Merchant Account: Mark Default Authorization Account" record operation.

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN Input parameter indicating the ID of the record being updated.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the update.

Definition

Copy


                    CREATE procedure dbo.USP_RECORDOPERATION_MERCHANTACCOUNTMARKDEFAULTAUTHORIZATIONACCOUNT
                    (
                        @ID uniqueidentifier,
                        @CHANGEAGENTID uniqueidentifier = null
                    )
                    as
                        set nocount on

                        if @CHANGEAGENTID is null
                            exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output

                        declare @CURRENTDATE datetime
                        set @CURRENTDATE = getdate()

                        begin try
                            -- Clear any other merchant accounts that may have been marked as the default

                            update dbo.MERCHANTACCOUNT set
                                ISDEFAULTAUTHORIZATIONACCOUNT = 0,
                                CHANGEDBYID = @CHANGEAGENTID,
                                DATECHANGED = @CURRENTDATE
                            where 
                                ID <> @ID and 
                                ISDEFAULTAUTHORIZATIONACCOUNT = 1

                            update dbo.MERCHANTACCOUNT set
                                ISDEFAULTAUTHORIZATIONACCOUNT = 1,
                                CHANGEDBYID = @CHANGEAGENTID,
                                DATECHANGED = @CURRENTDATE
                            where 
                                ID = @ID

                            -- The merchant account may not be in the DB yet so insert it if needed

                            if @@ROWCOUNT = 0
                                insert into dbo.MERCHANTACCOUNT 
                                (
                                    ID,
                                    ISDEFAULTAUTHORIZATIONACCOUNT,
                                    DATEADDED,
                                    DATECHANGED,
                                    ADDEDBYID,
                                    CHANGEDBYID
                                )
                                values
                                (
                                    @ID,
                                    1,
                                    @CURRENTDATE,
                                    @CURRENTDATE,
                                    @CHANGEAGENTID,
                                    @CHANGEAGENTID
                                )
                        end try
                        begin catch
                            exec dbo.USP_RAISE_ERROR
                            return 1
                        end catch                            

                        return 0