I am working on integrating braintree payments into our Spring-MVC based app. We have subscriptions in our application which are charged on monthly basis unless canceled by the user. However, there might be a situation when the payment doesn't go through on next billing cycle and we would like to cancel the services offered.
The approach I have taken is to get a list of all subscriptions which are currently active and track their status. Based upon that, we either let the service exist or run cancellation code.
Is this approach sufficient the way it is mentioned below?
Code :
#Override
#Scheduled(cron = "0 4 5 * * ?")
public void checkIfSubscriptionIsActive() {
List<Payment> paymentList = this.paymentDAO.getAllPayments();
for(Payment payment : paymentList){
Subscription subscription = gateway.subscription().find(payment.getPaypalId());
if(subscription!=null){
Subscription.Status status = subscription.getStatus();
if(status!=null){
if(status.toString().equals("Canceled")||(status.toString().equals("Expired"))||
(status.toString().equals("Past Due"))||(status.toString().equals("Pending"))||
(status.toString().equals("Unrecognized"))){
//Cancel service code
}
}
}
}
}
Related
I have an android application that does not have login / register structure but users can start subscription with in-app purchase.
I want to be able to recognize the user on different devices where the user logs in with the same play store account. So I want to be able to uniquely identify a user through the play store account.
Since my application is in the child and family category, I cannot access AccountManager-style sensitive data.
How can I do that. Does anyone have great ideas?
There is a great library which I hope will help you solve your problem as I'm already using it in some products.
You can try This library
This library perfectly handles Subscriptions as well as Purchases with and without payload. you just have to place implementation 'com.anjlab.android.iab.v3:library:1.0.44' in your build.gradle and you are good to go.
When your build.gradle is ready, implement BillingProcessor.IBillingHandler with your activity.
Then intialize your billing processor by placing this code in onCreate.
bp = new BillingProcessor(this, "YOUR LICENSE KEY FROM GOOGLE PLAY CONSOLE HERE", this);
bp.initialize();
You will get the following override methods,
#Override
public void onBillingInitialized() {
/*
* Called when BillingProcessor was initialized and it's ready to purchase
*/
}
#Override
public void onProductPurchased(String productId, TransactionDetails details) {
/*
* Called when requested PRODUCT ID was successfully purchased
*/
}
#Override
public void onBillingError(int errorCode, Throwable error) {
/*
* Called when some error occurred. See Constants class for more details
*
* Note - this includes handling the case where the user canceled the buy dialog:
* errorCode = Constants.BILLING_RESPONSE_RESULT_USER_CANCELED
*/
}
#Override
public void onPurchaseHistoryRestored() {
/*
* Called when purchase history was restored and the list of all owned PRODUCT ID's
* was loaded from Google Play
*/
}
Here is the trick, onPurchaseHistoryRestored is the actual method you are looking for. This method will get called whenever there is a subscription or purchase already available against a specific email. This library will automatically handle it for you. Let me know if it help you.
Don't forget to add this <uses-permission android:name="com.android.vending.BILLING" /> permission in your Manifest.
If you want to query the subscription status of users who log in to the same account on different devices, you can use the BillingClient.queryPurchases() interface to query the subscription status. If the interface returns a subscription, it is within the subscription validity period, and you need to continue providing services.
I am trying to do a Splunk Seach from Splunk java SDK. Here is the working code. My question is do I need to close service after each search. If yes, how to close it? Else is there a maximum number of jobs that I can create in each service?
ServiceArgs serviceArgs = new ServiceArgs();
serviceArgs.setUsername(splunkUserName);
serviceArgs.setHost(splunkHostname);
serviceArgs.setPort(Integer.parseInt(splunkPort));
serviceArgs.setPassword(splunkPassword));
HttpService.setSslSecurityProtocol(SSLSecurityProtocol.TLSv1_2);
Service service = Service.connect(serviceArgs);
JobArgs jobArgs = new JobArgs();
jobArgs.setExecutionMode(JobArgs.ExecutionMode.NORMAL);
jobArgs.setEarliestTime(startDate);
jobArgs.setLatestTime(endData);
jobArgs.setMaximumCount(maxResultCount);
Job job = service.getJobs().create(query,jobArgs);
My question is do I need to close service after each search
I would say it depends on your needs, I don't know well enough your application.
If yes, how to close it?
Anyway, you can : the com.splunk.Service have a logout method for this :
/**
* Forgets the current session token.
*
* #return The current {#code Service} instance.
*/
public Service logout() {
this.token = null;
this.removeAllCookies();
return this;
}
Else is there a maximum number of jobs that I can create in each service?
I would say yes, it should be the same limitation that the user have by making search through th UI.
I hope all is well. I'm fairly new to programming, and my school doesn't offer the appropriate level of Android Development to teach me what I need to know. So please do not mark this down because of "guidelines", I'm just trying to get some help. My instructors refuse to help because they aren't legally allowed to teach what is not offered. So please, please, please do not mark this down.
I am attempting to accept a Stripe payment on my mobile application. I am using ParseServer/Bitnami, and I have made it far enough to send and retrieve the tokenId to charge the card. I just haven't figured out how to charge the card. Please help.
Card userCard = new Card(num, expiryMonth, expiryYear, cvc);
// Test the data.
if (userCard.validateCard()) {
Stripe stripe = new Stripe(CardActivity.this, "pk_live_----REMOVED FOR SECURITY");
stripe.createToken(
userCard,
new TokenCallback() {
public void onSuccess(final Token token) {
// Get the current user.
ParseUser user = ParseUser.getCurrentUser();
String tokenId = token.getId();
// Update the token.
user.put("tokenId", tokenId);
/*Map<String, Object> params = new HashMap<>();
params.put("currency", "usd");
params.put("interval", "month");
params.put("name", "Membership");
params.put("amount", 9.99);
params.put("id", user.getObjectId());*/
user.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
Toast.makeText(CardActivity.this, "Success", Toast.LENGTH_SHORT).show();
}
});
}
public void onError(Exception error) {
// Show error message
Toast.makeText(CardActivity.this,
error.getMessage(),
Toast.LENGTH_LONG
).show();
}
}
);
}
So to build a transaction or create a charge (either as a one-off charge or through a recurring subscription) there are actually two phases.
The first phase is called the "Capture and Tokenization Phase". That's where we use information about the credit card (or other payment source) to create a special string to represent the actual details of the card. I like to think of these tokens as more of a codeword (maybe I just watch too many movies)-- the Crow Flies at Midnight. It's a special way for both you and Stripe to know what card you're referring to, without anyone else being able to eavesdrop and figure out any sensitive information. You do this phase with Stripe.js [1], Elements [2], Checkout [3], or your mobile SDK [4][5]. This phase uses your Publishable API Key and happens on a front-end (HTML/Javascript or Mobile).
The second phase is the "Storing or Charging Phase". You can take that special token or codeword that we made earlier and then either (a) charge it for a particular amount of money or (b) attach it to a Customer and store it for later. Either approach requires that you use the Stripe API on your backend. The alternative would be to use a Plugin or Integration to do all of this legwork for you. This phase uses your Secret API Key and happens on a backend web service (PHP, Python, Ruby, etc.)
To create a recurring charge or attach the payment source to a Customer, you would use the Create a Customer [6] API Endpoint. The source-argument would be the Token ID, generated in the first phase. Then you would use the Create a Charge [7] API Endpoint with a customer-argument equal to the Customer ID you've created.
Alternatively, to create a one-off charge, you could simply pass the source-argument to the Create a Charge [7] API Endpoint without a customer-argument.
Meaning-- you're missing the last step here-- you need to pass your retrieved token to a backend server that you control to make the charge.
Hope that helps!
[1] https://stripe.com/docs/stripe.js/v2
[2] https://stripe.com/docs/elements
[3] https://stripe.com/docs/checkout
[4] https://stripe.com/docs/mobile/ios
[5] https://stripe.com/docs/mobile/android
[6] https://stripe.com/docs/api#create_customer
[7] https://stripe.com/docs/api#create_charge
I am working on a Spring-MVC application in which there is Service desk functionality I am working on. So, as a part of Service desk, users can create issues and assign a support-team member. In that, they can also assign in how much time issue needs to be resolved. I am setting the time in java.sql.TimeStamp.
Now, when the time expires, I would like to send an email to the support-team admin, the person who created the issue and the support-team member responsible for resolving the issue.
If it was a normal scheduled or cron job, I can just write a #Scheduled method and get it over with, but here, I would like to check for example after 6 hours if the issue was resolved or not. How do I accomplish that? I have no idea to be honest.
Here is service layer part the SupportRequest :
#Service
#Transactional
public class SupportRequestServiceImpl implements SupportRequestService{
private final SupportRequestDAO supportRequestDAO;
#Autowired
public SupportRequestServiceImpl(SupportRequestDAO supportRequestDAO){
this.supportRequestDAO = supportRequestDAO;
}
#Autowired
private SupportTeamService supportTeamService;
#Override
public int addSupportRequest(SupportRequest supportRequest, int assignedTeamId, Long groupId) {
SupportTeam supportTeam = this.supportTeamService.getSupportTeamMemberById(assignedTeamId);
if(!(supportTeam == null)){
supportRequest.setCreationTime(new Timestamp(System.currentTimeMillis()));
supportRequest.setAssignedTeamMemberId(supportTeam.getTeamId());
return this.supportRequestDAO.addSupportRequest(supportRequest,groupId);
}
return 0;
}
}
I don't know what else to show. Thanks a lot.
Update
Will something like this work?
long delay = 1000*60*60*12; // after 12 hrs
Timer timer = new Timer();
Calendar cal = Calendar.getInstance();
timer.schedule(new TimerTask() {
public void run() {
// Task here ...
System.out.println("inside the main");
Integer id = new Integer(10);
Assert.assertNotNull(id);
}
}, delay);
For these kind of scenario, there should be background process running. That process will check for issues that has not been fixed in given time. Then this process will send a message to whoever you want and then continue running in background.
There are different ways of doing this.
1. Batch Process
You can make batch process. Batch process will be running on your server, it will check for expired issues and then send mail to the support-team admin.
2. Techniques for Real-time Updates
You can also you real time update techniques in spring. Using this technique you will fire request after every given period that will check for expire issues. If any issue found that has not been fixed you can send mail. Please read the related document here : Spring MVC 3.2 Preview: Techniques for Real-time Updates
3. Web Socket
Web socked can also be useful for these kind of task. Find the good source here :
SPRING FRAMEWORK 4.0 M2: WEBSOCKET MESSAGING ARCHITECTURES
My Requirement is to sent a mail to the concerned users when a record is created. The mail contains a link to our system that lets the user interacting with the system without login. The link expires after a certain time. The mailing is done using javax.mail.
How can I expire the link?
Use Timer#schedule(int):
// Schedule the timer to run once in 1 minute.
new Timer()
{
#Override
public void run()
{
if(remove)
{
// Either remove it
anchor.removeFromParent();
}
else
{
// Or disable it
anchor.setEnabled(false);
}
}
}.schedule(60 * 1000);
I would generate a key/ID that you add to the link and also store to a database. With filters (web.xml) you can check if the URL (ID) is still valid and pass it on to the desired page.
If you provide us with more details, we can give you a more detailed answer.