|
| 1 | +/** |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +package org.fineract.messagegateway.sms.providers.impl.infobip; |
| 20 | + |
| 21 | +import org.fineract.messagegateway.sms.domain.SMSMessage; |
| 22 | +import org.fineract.messagegateway.sms.repository.SmsOutboundMessageRepository; |
| 23 | +import org.fineract.messagegateway.sms.util.SmsMessageStatusType; |
| 24 | +import org.slf4j.Logger; |
| 25 | +import org.slf4j.LoggerFactory; |
| 26 | +import org.springframework.beans.factory.annotation.Autowired; |
| 27 | +import org.springframework.http.HttpStatus; |
| 28 | +import org.springframework.http.ResponseEntity; |
| 29 | +import org.springframework.web.bind.annotation.ModelAttribute; |
| 30 | +import org.springframework.web.bind.annotation.PathVariable; |
| 31 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 32 | +import org.springframework.web.bind.annotation.RequestMethod; |
| 33 | +import org.springframework.web.bind.annotation.RestController; |
| 34 | + |
| 35 | +import infobip.api.model.sms.mt.reports.SMSReport; |
| 36 | +import infobip.api.model.sms.mt.reports.SMSReportResponse; |
| 37 | + |
| 38 | +@RestController |
| 39 | +@RequestMapping("/infobip") |
| 40 | +public class InfoBipApiResource { |
| 41 | + |
| 42 | + private static final Logger logger = LoggerFactory.getLogger(InfoBipApiResource.class); |
| 43 | + |
| 44 | + private final SmsOutboundMessageRepository smsOutboundMessageRepository ; |
| 45 | + |
| 46 | + @Autowired |
| 47 | + public InfoBipApiResource(final SmsOutboundMessageRepository smsOutboundMessageRepository) { |
| 48 | + this.smsOutboundMessageRepository = smsOutboundMessageRepository ; |
| 49 | + } |
| 50 | + |
| 51 | + @RequestMapping(value = "/report/{messageId}", method = RequestMethod.POST, consumes = {"application/json"}, produces = {"application/json"}) |
| 52 | + public ResponseEntity<Void> updateDeliveryStatus(@PathVariable("messageId") final Long messageId, @ModelAttribute final SMSReportResponse payload) { |
| 53 | + SMSMessage message = this.smsOutboundMessageRepository.findOne(messageId) ; |
| 54 | + if(message != null) { |
| 55 | + SMSReport report = payload.getResults().get(0) ; |
| 56 | + logger.info("Status Callback received from InfoBip for "+messageId+" with status:"+report.getStatus()); |
| 57 | + logger.info("Status Callback received from InfoBip for "+messageId+" with messageid:"+report.getMessageId()); |
| 58 | + logger.info("Status Callback received from InfoBip for "+messageId+" with groupname:"+report.getStatus().getGroupName()); |
| 59 | + logger.info("Status Callback received from InfoBip for "+messageId+" with name:"+report.getStatus().getName()); |
| 60 | + logger.info("Status Callback received from InfoBip for "+messageId+" with groupname:"+report.getStatus().getAction()); |
| 61 | + message.setDeliveryStatus(SmsMessageStatusType.DELIVERED.getValue()); |
| 62 | + this.smsOutboundMessageRepository.save(message) ; |
| 63 | + }else { |
| 64 | + logger.info("Message with Message id "+messageId+" Not found"); |
| 65 | + } |
| 66 | + return new ResponseEntity<>(HttpStatus.NO_CONTENT); |
| 67 | + } |
| 68 | +} |
0 commit comments