[Home] [Help]
PACKAGE BODY: APPS.AR_CC_REFUNDS
Source
1 PACKAGE BODY AR_CC_REFUNDS AS
2 /* $Header: ARCCRFDB.pls 120.17 2005/09/14 10:53:48 sgnagara ship $ */
3
4 PG_DEBUG varchar2(1) := NVL(FND_PROFILE.value('AFLOG_ENABLED'), 'N');
5
6 PROCEDURE handle_exception (
7 p_return_status in varchar2,
8 p_msg_count in number,
9 p_vend_err_mesg in out NOCOPY varchar2,
10 p_context in varchar2) IS
11
12 v_msg_data varchar2(2000);
13 v_msg_index_out number;
14 v_error varchar2(2000);
15 v_error_description varchar2(4000);
16
17 BEGIN
18
19
20 /*
21 FOR i in 1..p_msg_count loop
22 v_error := fnd_msg_pub.get(i);
23 v_error_description := v_error_description || ':' || v_error;
24 END LOOP;
25 */
26
27 IF p_vend_err_mesg IS NULL THEN
28 IF p_return_status <> FND_API.G_RET_STS_SUCCESS then
29 IF (FND_MSG_PUB.Count_Msg > 1) then
30 -- More than one error message
31 FOR j in 1..FND_MSG_PUB.Count_Msg LOOP
32 FND_MSG_PUB.Get(
33 p_msg_index=>j,
34 p_encoded=>'F',
35 p_data=>v_msg_data,
36 p_msg_index_out=>v_msg_index_out);
37 v_error_description := v_error_description || ':' || v_msg_data;
38 END LOOP;
39 ELSE
40 -- Only one error message
41 FND_MSG_PUB.Get(
42 p_msg_index=>1,
43 p_encoded=>'F',
44 p_data=>v_msg_data,
45 p_msg_index_out=>v_msg_index_out);
46 v_error_description := v_error_description || v_msg_data;
47 END IF;
48 -- p_vend_err_mesg := p_context || ' ' ||v_error_description;
49 END IF;
50 p_vend_err_mesg := substr(p_context || ' ' ||v_error_description, 1, 240);
51 ELSE
52 p_vend_err_mesg := substr(p_context || ' ' ||p_vend_err_mesg, 1, 240);
53 END IF;
54
55
56 END handle_exception;
57
58 PROCEDURE process_refund(
59 cc_currency IN VARCHAR2,
60 cc_price IN VARCHAR2,
61 cc_pay_server_order_num IN OUT NOCOPY VARCHAR2,
62 cc_unique_reference IN VARCHAR2,
63 cc_merchant_id IN VARCHAR2,
64 cc_pmt_instr_id IN VARCHAR2,
65 cc_pmt_instr_exp IN VARCHAR2,
66 cc_status_code IN OUT NOCOPY VARCHAR2,
67 cc_statusmsg IN OUT NOCOPY VARCHAR2,
68 cc_err_location IN OUT NOCOPY VARCHAR2,
69 cc_vend_err_code IN OUT NOCOPY VARCHAR2,
70 cc_vend_err_mesg IN OUT NOCOPY VARCHAR2,
71 cc_return_status IN OUT NOCOPY VARCHAR2,
72 cc_cash_receipt_id IN VARCHAR2 DEFAULT NULL
73 ) IS
74
75 p_api_version NUMBER := 1.0;
76 p_init_msg_list VARCHAR2(2000) := FND_API.G_FALSE;
77 p_commit VARCHAR2(30) := FND_API.G_FALSE;
78 p_validation_level NUMBER := FND_API.G_VALID_LEVEL_FULL;
79 p_ecapp_id NUMBER := 222;
80
81 cc_status VARCHAR2(2000);
82 x_msg_count NUMBER; /* output message count */
83 x_msg_data VARCHAR2(2000); /* reference string for
84 output message text */
85 cc_iby_trxn_id NUMBER;
86 cc_iby_trxn_pson VARCHAR2(50);
87
88 /* Records for Credit Card Payment Return */
89 cc_returntrxn_rec iby_payment_adapter_pub.returntrxn_rec_type;
90 cc_returnresp_rec iby_payment_adapter_pub.returnresp_rec_type;
91
92 /* Records for Credit Card Payment Credit */
93
94 cc_payee_rec iby_payment_adapter_pub.Payee_rec_type ;
95 cc_pmtinstr_rec iby_payment_adapter_pub.PmtInstr_rec_type ;
96 cc_tangible_rec iby_payment_adapter_pub.Tangible_rec_type ;
97 cc_credittrxn_rec iby_payment_adapter_pub.CreditTrxn_rec_type ;
98 cc_creditresp_rec iby_payment_adapter_pub.CreditResp_rec_type ;
99
100
101 CURSOR cc_iby_trxn_id_cur IS
102 SELECT DISTINCT transactionid
103 FROM iby_trans_all_v
104 WHERE tangibleid = cc_pay_server_order_num;
105
106 /* Added for Bug 3646482 */
107
108 CURSOR cc_iby_dup_cur IS
109 SELECT DISTINCT tangibleid
110 FROM iby_trans_all_v
111 WHERE trxnref = cc_unique_reference
112 AND reqtype = 'ORAPMTCREDIT';
113
114 BEGIN
115
116 IF PG_DEBUG in ('Y', 'C') THEN
117 fnd_file.put_line(FND_FILE.LOG, 'ar_cc_refunds.process_refund()+');
118 END IF;
119
120 /* Assign the input parameter to global variable **/
121 g_cash_receipt_id := cc_cash_receipt_id;
122 /* Print input parameters */
123 /* bug3771406 */
124 IF PG_DEBUG in ('Y', 'C') THEN
125 arp_file.write_log('Cash Receipt Id : [' || cc_cash_receipt_id ||']');
126 arp_file.write_log('g_cash_receipt_id :[' || g_cash_receipt_id ||']');
127 arp_file.write_log('PSON :[' || cc_pay_server_order_num ||']');
128 arp_file.write_log('cc_currency : [' || cc_currency ||']');
129 arp_file.write_log('cc_merchant_id :[' || cc_merchant_id ||']');
130 arp_file.write_log('cc_pmt_instr_id :[' || substrb(cc_pmt_instr_id,1,4) ||']');
131 arp_file.write_log('cc_pmt_instr_exp :[' || cc_pmt_instr_exp ||']');
132 END IF;
133 /* FETCH iPayment Transactionid */
134
135 OPEN cc_iby_trxn_id_cur;
136 FETCH cc_iby_trxn_id_cur INTO cc_iby_trxn_id;
137
138 IF cc_iby_trxn_id_cur%NOTFOUND then
139 /* return error conditions */
140 cc_vend_err_code := '1 PMT-TRXN ERR';
141 cc_vend_err_mesg := 'Error in In getting trxn_id';
142 Return;
143 END IF;
144
145 CLOSE cc_iby_trxn_id_cur;
146
147 /* BEGIN Credit Card Payment Return */
148
149 /* ASSIGN Values to Payment Return Api Record Variables */
150
151
152 cc_returntrxn_rec.trxn_id := TO_NUMBER(cc_iby_trxn_id);
153 cc_returntrxn_rec.pmtmode := 'ONLINE';
154 cc_returntrxn_rec.settlement_date := NULL;
155 cc_returntrxn_rec.currency := cc_currency ;
156 cc_returntrxn_rec.price := ABS(cc_price) ;
157 cc_returntrxn_rec.nls_lang := NULL;
158 cc_returntrxn_rec.TrxnRef := cc_unique_reference;
159
160 IF PG_DEBUG in ('Y', 'C') THEN
161 arp_file.write_log('Calling iby_payment_adapter_pub.OraPmtReturn()+..');
162 END IF;
163
164 /* Call Payment return API */
165 BEGIN
166 iby_payment_adapter_pub.orapmtreturn (
167 p_api_version => p_api_version
168 ,p_init_msg_list => p_init_msg_list
169 ,p_commit => p_commit
170 ,p_validation_level => p_validation_level
171 ,p_ecapp_id => p_ecapp_id
172 ,p_returntrxn_rec => cc_returntrxn_rec
173 ,x_return_status => cc_return_status
174 ,x_msg_count => x_msg_count
175 ,x_msg_data => x_msg_data
176 ,x_retresp_rec => cc_returnresp_rec );
177
178
179 cc_status := cc_returnresp_rec.response.status;
180 cc_status_code := cc_returnresp_rec.response.errcode;
181 cc_statusmsg := cc_returnresp_rec.response.errmessage;
182
183 cc_err_location := cc_returnresp_rec.errorlocation;
184 cc_vend_err_code := cc_returnresp_rec.beperrcode;
185 cc_vend_err_mesg := cc_returnresp_rec.beperrmessage;
186
187 EXCEPTION
188 WHEN OTHERS THEN
189 cc_vend_err_code := '2 PMT-RETURN ERR';
190 -- cc_vend_err_mesg := 'Error in Return api';
191 handle_exception(cc_return_status,
192 x_msg_count,
193 cc_vend_err_mesg,
194 'Exception in Return api: ');
195 Return;
196 END;
197 IF PG_DEBUG in ('Y', 'C') THEN
198 arp_file.write_log('OraPmtReturn return status..'||cc_return_status);
199 arp_file.write_log('OraPmtReturn status code..'||cc_status_code);
200 arp_file.write_log('iby_payment_adapter_pub.OraPmtReturn()-');
201 END IF;
202
203 /* Check the return status. An S means Success. If it failed
204 when need to check the status code as you can only give a
205 refund once per PSON (Payment Server Order Number). Any
206 additional refund must be treated as a Credit and given its
207 own PSON number */
208
209 /* Bug 2503608 - Removed the ELSE part of the IF statement
210 which was going to error even if it is success.*/
211
212 /* Bug 2777278 - Included error codes IBY_0002, 20604
213 and 50308 for duplicate refunds */
214
215 /* bug 3646482. IBY_20402 error has to be treated as success in AR side */
216 IF cc_return_status <> 'S' THEN
217 IF cc_status_code = 'IBY_20402' THEN
218 cc_return_status := 'S';
219 RETURN;
220 ELSIF cc_status_code = 'IBY_204460' OR
221 cc_status_code = 'IBY_0002' OR
222 cc_status_code = 'IBY_20604' OR
223 cc_status_code = 'IBY_50308'
224 THEN
225 /* we need to begin the CREDIT process instead of REFUND */
226 IF PG_DEBUG in ('Y', 'C') THEN
227 arp_file.write_log('We need to begin the CREDIT process instead of REFUND ');
228 END If;
229
230 /* Clear out NOCOPY variable used in Refund Call */
231 cc_return_status := NULL;
232 cc_status := NULL;
233 cc_status_code := NULL;
234 cc_statusmsg := NULL;
235 cc_err_location := NULL;
236 cc_vend_err_code := NULL;
237 cc_vend_err_mesg := NULL;
238
239 cc_iby_trxn_pson := null;
240
241 /* since we need a new PSON number, we also need to clear that
242 out NOCOPY and retrieve a new one */
243 cc_pay_server_order_num := NULL;
244
245 OPEN cc_iby_dup_cur;
246 FETCH cc_iby_dup_cur INTO cc_iby_trxn_pson;
247
248 IF cc_iby_trxn_pson is not null THEN
249 cc_pay_server_order_num := cc_iby_trxn_pson;
250 IF PG_DEBUG in ('Y', 'C') THEN
251 arp_file.write_log('Corrected PSON is..'||cc_pay_server_order_num);
252 END IF;
253
254 ELSIF cc_iby_dup_cur%NOTFOUND THEN
255
256 SELECT 'AR_'||ar_payment_server_ord_num_s.nextval
257 INTO cc_pay_server_order_num
258 FROM DUAL;
259 IF PG_DEBUG in ('Y', 'C') THEN
260 arp_file.write_log('Generated PSON is..'||cc_pay_server_order_num);
261 END IF;
262 END IF;
263
264 /* ASSIGN Values to Credit Card Credit Api Record Variables */
265
266 cc_payee_rec.payee_id := cc_merchant_id;
267
268 /* cc_pmtinstr_rec.creditcardinstr.cc_num := cc_pmt_instr_id; Bug-4606039 */
269 -- Bugfix 2976396.
270 /* Follwing statement commented for bug 3646482. ADD_MONTHS returns INVALID MONTH error. Next statement is added instead. */
271 /* cc_pmtinstr_rec.creditcardinstr.cc_expdate := ADD_MONTHS(to_date(cc_pmt_instr_exp, 'MM/YYYY'),1) -1 ; */
272 /* Bug-4606039
273 cc_pmtinstr_rec.creditcardinstr.cc_expdate := last_day(to_date(cc_pmt_instr_exp,'DD-MM-YY')); */
274
275 cc_tangible_rec.tangible_id := cc_pay_server_order_num;
276 cc_tangible_rec.tangible_amount := ABS(cc_price);
277 cc_tangible_rec.currency_code := cc_currency;
278
279 cc_credittrxn_rec.pmtmode := 'ONLINE' ;
280 cc_credittrxn_rec.TrxnRef := cc_unique_reference;
281
282 IF PG_DEBUG in ('Y', 'C') THEN
283 arp_file.write_log('Calling iby_payment_adapter_pub.OraPmtCredit()+...');
284 END IF;
285
286 /* Call Credit API */
287 iby_payment_adapter_pub.OraPmtCredit (
288 p_api_version => p_api_version
289 ,p_init_msg_list => p_init_msg_list
290 ,p_commit => p_commit
291 ,p_validation_level => p_validation_level
292 ,p_ecapp_id => p_ecapp_id
293 ,p_payee_rec => cc_payee_rec
294 ,p_pmtinstr_rec => cc_pmtinstr_rec
295 ,p_tangible_rec => cc_tangible_rec
296 ,p_credittrxn_rec => cc_credittrxn_rec
297 ,x_return_status => cc_return_status
298 ,x_msg_count => x_msg_count
299 ,x_msg_data => x_msg_data
300 ,x_creditresp_rec => cc_creditresp_rec
301 );
302
303 cc_status := cc_creditresp_rec.response.status;
304 cc_status_code := cc_creditresp_rec.response.errcode;
305 cc_statusmsg := cc_creditresp_rec.response.errmessage;
306
307 cc_err_location := cc_creditresp_rec.errorlocation;
308 cc_vend_err_code := cc_creditresp_rec.beperrcode;
309 cc_vend_err_mesg := cc_creditresp_rec.beperrmessage;
310
311
312 /* Bug 2976396. Modified Exceptions block into IF clause
313 since the api orapmtcredit does not throw any exception.
314 */
315 /* Following condition added for bug 3646482. IBY_20402 has to be treated as success */
316
317 IF (cc_return_status <> FND_API.G_RET_STS_SUCCESS) AND (cc_status_code = 'IBY_20402') THEN
318 IF PG_DEBUG in ('Y', 'C') THEN
319 arp_file.write_log('OraPmtCredit API returned status code..'||cc_status_code);
320 END IF;
321 cc_return_status := FND_API.G_RET_STS_SUCCESS;
322 RETURN;
323 END IF;
324
325 IF (cc_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
326
327 IF( cc_vend_err_code IS NULL) THEN
328 cc_vend_err_code := '3 PMT-RETURN ERR'; /* bug4220521 */
329 cc_vend_err_mesg := 'Error in Return api';
330 END IF;
331
332 handle_exception(cc_return_status,
333 x_msg_count,
334 cc_vend_err_mesg,
335 'Exception in Credit api: ');
336 Return;
337 END IF;
338 IF PG_DEBUG in ('Y', 'C') THEN
339 arp_file.write_log('iby_payment_adapter_pub.OraPmtCredit()-');
340 END IF;
341 ELSE
342 IF( cc_vend_err_code IS NULL) THEN
343 cc_vend_err_code := '4 PMT-RETURN ERR'; /* bug4220521 */
344 cc_vend_err_mesg := 'Error in Return api';
345 END IF;
346
347 handle_exception(cc_return_status,
348 x_msg_count,
349 cc_vend_err_mesg,
350 'Error in Return api (' || cc_status_code || '): ');
351 Return;
352 END IF;
353
354 END IF;
355
356 IF PG_DEBUG in ('Y', 'C') THEN
357 fnd_file.put_line(FND_FILE.LOG, 'ar_cc_refunds.process_refund()+');
358 END IF;
359
360 END process_refund;
361
362 END;