Subversion Repositories SmartDukaan

Rev

Rev 8583 | Rev 8899 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1946 chandransh 1
<?xml version="1.0" encoding="UTF-8"?>
2
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
3
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
4
 
5
<mapper namespace="in.shop2020.payment.persistence.PaymentMapper">
6
 
7
  <resultMap type="payment" id="paymentResult">
8
    <id property="id" column="id"/>
9
    <collection property="attributes" javaType="ArrayList" column="id" ofType="paymentAttribute" select="getAttributesForPayment"/>
10
  </resultMap>
11
 
12
  <insert id="insertPayment" parameterType="payment" useGeneratedKeys="true" keyProperty="id">
13
    INSERT INTO payment
6077 anupam.sin 14
      (gatewayId, userId, merchantTxnId, amount, status, initTimestamp, isDigital) 
1946 chandransh 15
    VALUES
6077 anupam.sin 16
      (#{gatewayId}, #{userId}, #{merchantTxnId}, #{amount}, #{status},  now(), #{isDigital})
1946 chandransh 17
  </insert>
18
 
19
  <insert id="insertPaymentAttribute" parameterType="map">
20
    INSERT INTO paymentattribute
21
      (payment_id, name, value)
22
    VALUES(#{paymentId}, #{name}, #{value})
23
    ON DUPLICATE KEY UPDATE value=values(value);
24
  </insert>
25
 
26
  <update id="updatePayment" parameterType="payment">
27
    UPDATE payment
2388 chandransh 28
    SET
29
    <if test="gatewayPaymentId != null">
30
      gatewayPaymentId = #{gatewayPaymentId},
31
    </if>
32
    <if test="sessionId != null">
33
      sessionId = #{sessionId},
34
    </if>
35
    <if test="gatewayTxnStatus != null">
36
      gatewayTxnStatus = #{gatewayTxnStatus},
37
    </if>
38
    <if test="description != null">
39
      description = #{description},
40
    </if>
41
    <if test="gatewayTxnId != null">
42
      gatewayTxnId = #{gatewayTxnId},
43
    </if>
44
    <if test="authCode != null">
45
      authCode = #{authCode},
46
    </if>
47
    <if test="referenceCode != null">
48
      referenceCode = #{referenceCode},
49
    </if> 
50
    <if test="gatewayTxnDate != null">
51
      gatewayTxnDate = #{gatewayTxnDate},
52
    </if>
53
    <if test="status != null">
54
      status = #{status},
55
    </if>
6503 rajveer 56
    <if test="refundAmount != null">
57
      refundAmount = #{refundAmount},
58
    </if>
1946 chandransh 59
    errorCode = #{errorCode},
60
    successTimestamp = #{successTimestamp},
4422 mandeep.dh 61
    errorTimestamp = #{errorTimestamp},
62
    provisionalCaptureTimestamp = #{provisionalCaptureTimestamp}
1946 chandransh 63
    WHERE id=#{id}
64
  </update>
65
 
66
  <sql id="selectAllPaymentFields">
67
    SELECT * FROM payment
68
  </sql>
69
 
70
  <select id="getPayment" parameterType="int" resultMap="paymentResult">
71
    <include refid="selectAllPaymentFields"/>
72
    WHERE id=#{id}
73
  </select>
74
 
75
  <select id="getPaymentForTxn" parameterType="int" resultMap="paymentResult">
76
    SELECT * FROM payment
77
    WHERE merchantTxnId=#{merchantTxnId}
8295 kshitij.so 78
    AND isDigital = 0 
2388 chandransh 79
    ORDER BY id DESC
80
    LIMIT 1
1946 chandransh 81
  </select>
82
 
7049 anupam.sin 83
  <select id="getPaymentForRechargeTxn" parameterType="int" resultMap="paymentResult">
84
  	SELECT * FROM payment
85
    WHERE merchantTxnId=#{merchantTxnId}
86
    AND isDigital = 1
87
    ORDER BY id DESC
88
    LIMIT 1
89
  </select>
90
 
2288 chandransh 91
  <sql id="getPaymentsWhereClause">
92
    <if test="fromTime != ''">
93
      initTimestamp &gt;= #{fromTime}
94
    </if>
8604 rajveer 95
    <if test="toTime != ''">
96
      AND initTimestamp &lt;= #{toTime}
97
    </if>
98
 
99
<!--
2289 chandransh 100
    <if test="toTime != '' &amp;&amp; status == 0">
2288 chandransh 101
      AND initTimestamp &lt;= #{toTime}
102
    </if>
8604 rajveer 103
	<if test="toTime != '' &amp;&amp; status != 0">
2288 chandransh 104
      AND (errorTimestamp &lt;= #{toTime} OR successTimestamp &lt;= #{toTime})
105
    </if>
8604 rajveer 106
 -->
2288 chandransh 107
    <if test="status != -1">
108
      AND status=#{status}
109
    </if>
110
    <if test="gatewayId != 0">
111
      AND gatewayId = #{gatewayId}
112
    </if>
113
  </sql>
114
 
1946 chandransh 115
  <select id="getPayments" parameterType="map" resultMap="paymentResult">
116
    SELECT * FROM payment
117
    <where>
2288 chandransh 118
      <include refid="getPaymentsWhereClause"/>
1946 chandransh 119
    </where>
120
    ORDER BY id
121
  </select>
122
 
4141 chandransh 123
  <select id="getPaymentsByCapturedDate" parameterType="map" resultMap="paymentResult">
124
    SELECT * FROM payment
125
    <where>
126
      status = #{status}
127
	  <if test="fromTime != ''">
128
	    AND successTimestamp &gt;= #{fromTime}
129
	  </if>
130
	  <if test="toTime != ''">
131
	    AND successTimestamp &lt;= #{toTime}
132
	  </if>
133
	  <if test="gatewayId != 0">
134
        AND gatewayId = #{gatewayId}
135
      </if>
136
    </where>
137
    ORDER BY id
138
  </select>
139
 
1946 chandransh 140
  <select id="getPaymentsForUser" parameterType="map" resultMap="paymentResult">
141
    SELECT * FROM payment
142
    <where>
2288 chandransh 143
      <include refid="getPaymentsWhereClause"/>
144
      AND userId=#{userId}
1946 chandransh 145
    </where>
146
    ORDER BY id
147
  </select>
148
 
149
  <select id="getMinMaxPaymentAmount" resultType="hashmap">
2293 chandransh 150
    SELECT MIN(AMOUNT) MIN, MAX(AMOUNT) MAX from payment WHERE status = 2
1946 chandransh 151
  </select>
152
 
153
  <select id="getAttributesForPayment" parameterType="int" resultType="paymentAttribute">
154
    SELECT * FROM paymentattribute where payment_id = #{id}
155
  </select>
156
</mapper>