How to delete a credit card using the USAEPAY Web service? - java

I am using the USAEPAY Web service for credit card services, including adding, updating and deleting credit cards. Adding/updating works fine, however the credit card deletion results in the error:
com.usaepay.api.jaxws.GeneralFault_Exception: 40030: Customer Not Found
It is quite strange because I check the customer number in all other operations and this number is the same and it works
Code example
Add credit card:
public void addPaymentMethodToCustomer(String customerNum, SavedCreditCardInfo savedCreditCardInfo, Address address) {
UeSecurityToken securityToken = getSecurityToken(null);
PaymentMethod paymentMethod = createUSAEPaymentMethod(savedCreditCardInfo, address);
BigInteger paymentMethodID = null;
if(securityToken != null) {
try {
UeSoapServerPortType client = getClient();
paymentMethodID = client.addCustomerPaymentMethod(securityToken, new BigInteger(customerNum), paymentMethod, false, false);
} catch (Exception e) {
LOG.error("Unable to add payment method for customer " + customerNum, e);
throw new AddPaymentMethodException("Unable to add payment method for USA E Pay customer num " + customerNum);
}
LOG.info("Succesfully added payment method for customer=" + customerNum + " with payment method=" + paymentMethodID );
}
}
Log:
INFO com.smartdestinations.service.payment.impl.USAEPayServiceImpl:288 - Succesfully added payment method for customer=25468380 with payment method=12184
Deletion:
public void deleteCustomerPaymentMethod(String paymentMethodId, String customerNum) {
UeSecurityToken securityToken = getSecurityToken(null);
if(securityToken != null) {
try {
UeSoapServerPortType client = getClient();
client.deleteCustomerPaymentMethod(securityToken, new BigInteger(customerNum), new BigInteger(paymentMethodId));
} catch (Exception e) {
LOG.error("Unable to delete payment method with customerNumber=" + customerNum + " and paymentID=" + paymentMethodId, e);
throw new DeletePaymentMethodException("Unable to delete payment with id " + paymentMethodId + " for customer " + customerNum);
}
}
}
Log:
com.smartdestinations.service.payment.impl.USAEPayServiceImpl:388 - Unable to delete payment method with customerNumber=25468380 and paymentID=12184
com.usaepay.api.jaxws.GeneralFault_Exception: 40030: Customer Not Found

It appeared to be a bug in USAEPAY. They promised to fix this bug

Related

Can I use DynamoDB Streams inside my Java Code to update/add data to my DynamoDB?

I am using AWS Lambda(written in Java) to get data from DyanamoDB using DynamoDB Streams and then processing this data. Now I want to store the response of this processed data in the same DynamoDB Table and against the same primary key. Is it possible to use Streams to update the data back in the table or do I need to separately create a DyanamoDB Connection and then write my data into it ?? Kindly Suggest. Here is the code which I have used to read data from Stream and process it. I want to store the Response Status Code and actual Response in DB.
public String handleRequest(DynamodbEvent ddbEvent, Context context) {
LambdaLogger logger = context.getLogger();
Map<String,AttributeValue> newRecord = null;
int index = 1;
for (DynamodbStreamRecord record : ddbEvent.getRecords()) {
logger.log("#######################################");
logger.log("Processing Record - " + (index++));
newRecord = record.getDynamodb().getNewImage();
logger.log("Record Details - " + newRecord);
String user = newRecord.get("user").getS();
String password = newRecord.get("password").getS();
String to = newRecord.get("to").getN();
String from = newRecord.get("from").getN();
String text = newRecord.get("text").getS();
logger.log("Username - "+ user + " Password - " + password + " To - " + to + " From - " + from + " Text - " + text);
String url = "http://www.sample.com";
HttpGet request = new HttpGet(url);
CloseableHttpClient httpClient = HttpClients.createDefault();
String result = "";
try {
CloseableHttpResponse response = httpClient.execute(request);
logger.log("Response Status Code - " + response.getStatusLine().toString());
HttpEntity entity = response.getEntity();
if (entity != null) {
result = EntityUtils.toString(entity);
logger.log("Response - " + result);
}
} catch(Exception e) {
logger.log(e.getMessage());
} finally {
try {
httpClient.close();
} catch (IOException e) {
logger.log(e.getMessage());
}
}
}
return "Successfully processed " + ddbEvent.getRecords().size() + ".";

Softlayer - list of servers which are powered on

The following java code lists all the bare metal servers in softlayer for a specific SL account and filters for servers which are powered on (e.g. powerState='on'.
public void listServers(Account.Service service, ApiClient client) throws Exception {
service.withMask().hardware().fullyQualifiedDomainName().primaryIpAddress();
service.withMask().hardware().hardwareStatus();
service.withMask().hardware().id();
Account account = service.getObject();
//
// list of softlayer servers for the client account
//
for (Hardware hardware : account.getHardware()) {
String hostname = hardware.getFullyQualifiedDomainName();
String hardwareStatus = (hardware.getHardwareStatus() == null) ? null : hardware.getHardwareStatus().getStatus();
Long serverId = hardware.getId();
String powerState = null;
if (serverId != null) {
Hardware.Service hardwareService = Hardware.service(client, serverId);
hardwareService.setMask("mask[serverPowerState");
try {
powerState = hardwareService.getServerPowerState();
} catch (Exception ex) {
System.out.println("Error, cannot get powerState, hostname=" + hostname + ", msg=" + ex.getMessage());
}
}
System.out.println("Hostname=" + hostname + ", hwStatus=" + hardwareStatus + ", powerState=" + powerState);
}
}
Code seems to work, but for at least one of the servers, it fails on the call to hardwareService.getServerPowerState()
"Unable to establish IPMI v2 / RMCP+ session".
Any ideas why this is failing ?

403 : Daily Limit for Unauthenticated Use Exceeded youtube api v3 java

I Know this question has been asked multiple times, but I couldn't find one working for me.
Basically I am trying to get a youtube video basic info which I get the proper result for that but then when I trigger to get the comments of that video the error pops out saying:
There was a service error: 403 : Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.
My code:
public String getyoutubeitemfull_details(String URI) throws SQLException, IOException{
try {
YouTube youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, new HttpRequestInitializer() {
#Override
public void initialize(HttpRequest request) throws IOException {
}
}).setApplicationName("APP_ID").build();
String apiKey = "API Key";
YouTube.Videos.List listVideosRequest = youtube.videos().list("statistics");
listVideosRequest.setId("qUvPzjSWMSM");
listVideosRequest.setKey(apiKey);
VideoListResponse listResponse = listVideosRequest.execute();
Video video = listResponse.getItems().get(0);
BigInteger viewCount = video.getStatistics().getViewCount();
BigInteger Likes = video.getStatistics().getLikeCount();
BigInteger DisLikes = video.getStatistics().getDislikeCount();
BigInteger Comments = video.getStatistics().getCommentCount();
System.out.println("[View Count] " + viewCount);
System.out.println("[Likes] " + Likes);
System.out.println("[Dislikes] " + DisLikes);
System.out.println("[Comments] " + Comments);
CommentThreadListResponse videoCommentsListResponse = youtube.commentThreads()
.list("snippet").setVideoId("qUvPzjSWMSM").setMaxResults(50l).setTextFormat("plainText").execute();
List<CommentThread> videoComments = videoCommentsListResponse.getItems();
for (CommentThread videoComment : videoComments) {
CommentSnippet snippet = videoComment.getSnippet().getTopLevelComment().getSnippet();
System.out.println(" - Author: " + snippet.getAuthorDisplayName());
System.out.println(" - Comment: " + snippet.getTextDisplay());
System.out.println("\n-------------------------------------------------------------\n");
}
} catch (GoogleJsonResponseException e) {
System.err.println("There was a service error: " + e.getDetails().getCode() + " : "
+ e.getDetails().getMessage());
} catch (IOException e) {
System.err.println("There was an IO error: " + e.getCause() + " : " + e.getMessage());
} catch (Throwable t) {
t.printStackTrace();
}
return null;
}
FYI: So much of question that I have been through so far talk about adding listVideosRequest.setKey(apiKey); which I have it done. I also Have enable OAuth 2.0 enabled in my google console.
Thanks to #DalmTo for throwing to its direction.
Basically Api Key doesn't have priviledges to retrieve comments and things like that. for deep priviledges I had to use Oauth, which basically is being created the same was as API Key but in Oauth you receive a client_secrets.json file containing: client secret, client ID and etc...
Then you call that in you code.
Note: Their is verious ways of calling you client_secrets.json file but it depends on your need.
My way: Reader clientSecretReader = new InputStreamReader(
new FileInputStream("/home/Downloads/src/client_secrets.json"));

How to fetch comments with most likes or replies on a YouTube video using YouTube Data API?

So far, I have managed to collect first 100 comments on a video using YouTube Data API in my Java program shown below.
public class CommentHandling {
/**
* Define a global instance of a YouTube object, which will be used to make
* YouTube Data API requests.
*/
private static YouTube youtube;
/**
* List, reply to comment threads; list, update, moderate, mark and delete
* replies.
*
* #param args command line args (not used).
*/
public static void main(String[] args) {
// This OAuth 2.0 access scope allows for full read/write access to the
// authenticated user's account and requires requests to use an SSL connection.
List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube.force-ssl");
try {
// Authorize the request.
Credential credential = Auth.authorize(scopes, "commentthreads");
// This object is used to make YouTube Data API requests.
youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential)
.setApplicationName("youtube-cmdline-commentthreads-sample").build();
// Prompt the user for the ID of a video to comment on.
// Retrieve the video ID that the user is commenting to.
String videoId = getVideoId();
System.out.println("You chose " + videoId + " to subscribe.");
// All the available methods are used in sequence just for the sake
// of an example.
// Call the YouTube Data API's commentThreads.list method to
// retrieve video comment threads.
CommentThreadListResponse videoCommentsListResponse = youtube.commentThreads()
.list("snippet, replies").setVideoId(videoId)
.setMaxResults(new Long(100)).setTextFormat("html").execute();
List<CommentThread> videoComments = videoCommentsListResponse.getItems();
if (videoComments.isEmpty()) {
System.out.println("Can't get video comments.");
} else {
// Print information from the API response.
System.out
.println("\n================== Returned Video Comments ==================\n");
for (CommentThread videoComment : videoComments) {
CommentSnippet snippet = videoComment.getSnippet().getTopLevelComment()
.getSnippet();
System.out.println(" - Author: " + snippet.getAuthorDisplayName());
System.out.println(" - Comment: " + snippet.getTextDisplay());
System.out
.println("\n-------------------------------------------------------------\n");
}
}
} catch (GoogleJsonResponseException e) {
System.err.println("GoogleJsonResponseException code: " + e.getDetails().getCode()
+ " : " + e.getDetails().getMessage());
e.printStackTrace();
} catch (IOException e) {
System.err.println("IOException: " + e.getMessage());
e.printStackTrace();
} catch (Throwable t) {
System.err.println("Throwable: " + t.getMessage());
t.printStackTrace();
}
}
/*
* Prompt the user to enter a video ID. Then return the ID.
*/
private static String getVideoId() throws IOException {
String videoId = "";
System.out.print("Please enter a video id: ");
BufferedReader bReader = new BufferedReader(new InputStreamReader(System.in));
videoId = bReader.readLine();
return videoId;
}
But I am interested in collecting the top comments (either by likes or replies on a comment) on a video. These are the comments which are usually on the first page of the video when sorted by using "Top comments" filter.
Any help would be highly appreciated.

How to remove deadlocks in orientdb

I am getting too many deadlocks on OrientDb while I am using Java API to query the vertices. After the deadlock happens, the entire database becomes unresponsive and I have to kill the daemon and start again. As example, the error that I get from deadlocks is :
com.orientechnologies.common.concur.OTimeoutException: Can not lock record for 2000 ms. seems record is deadlocked by other record
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.acquireReadLock(OAbstractPaginatedStorage.java:1300)
at com.orientechnologies.orient.core.tx.OTransactionAbstract.lockRecord(OTransactionAbstract.java:120)
at com.orientechnologies.orient.core.id.ORecordId.lock(ORecordId.java:282)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.lockRecord(OAbstractPaginatedStorage.java:1776)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.readRecord(OAbstractPaginatedStorage.java:1416)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.readRecord(OAbstractPaginatedStorage.java:694)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.executeReadRecord(ODatabaseDocumentTx.java:1569)
at com.orientechnologies.orient.core.tx.OTransactionNoTx.loadRecord(OTransactionNoTx.java:80)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.load(ODatabaseDocumentTx.java:1434)
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.readRecord(ONetworkProtocolBinary.java:1456)
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.executeRequest(ONetworkProtocolBinary.java:346)
at com.orientechnologies.orient.server.network.protocol.binary.OBinaryNetworkProtocolAbstract.execute(OBinaryNetworkProtocolAbstract.java:216)
at com.orientechnologies.common.thread.OSoftThread.run(OSoftThread.java:65)
Following is the block that I use to query edges and create associations between vertices
public User generateFriend(String mobile, String userRID) {
StringBuilder errorMsg = new StringBuilder();
Iterable<OrientVertex> vertexes;
//Retrieve friends of the user
List<User> friendsList = new ArrayList<User>();
vertexes = db.queryVertices("select expand( unionAll(inE('E_Friend').out,outE('E_Friend').in) ) from " + userRID,errorMsg);
if (!errorMsg.toString().equals("")) {
throw new DbException("Db exception occured, " + errorMsg);
}
for (OrientVertex v : vertexes){
friendsList.add(vertexToUser(v));
}
//Create edges if between the user and other users with mobile number in the list and if the edge is not yet created
User u = findUserByMobileNo(friendsList,mobile);
if ( u == null){
u = findByMobileNo(mobile);
if (u != null) {
//create edge
db.executeQuery("select createEdge('E_Friend','" + userRID + "','" + u.getRid() + "') from " + userRID, new HashMap<String, Object>(), errorMsg);
if (!errorMsg.toString().equals("")) {
throw new DbException("Db exception occured, " + errorMsg);
}
}
}
return u;
}
public Iterable<OrientVertex> queryVertices(String query, StringBuilder errMsg){
logger.error("before getGraph, " + errMsg.toString());
graph = getGraph(errMsg);
if (!errMsg.toString().equals("")){
return null;
}
logger.error("after getGraph, " + errMsg.toString());
Iterable<OrientVertex> vertices = null;
try {
OSQLSynchQuery<OrientVertex> qr = new OSQLSynchQuery<OrientVertex>(query);
vertices = graph.command(qr).execute();
logger.error("after graph command execute, " + errMsg.toString());
}
catch (Exception ex){
errMsg.append(ex.getMessage());
logger.error("graph command exception, " + errMsg.toString());
}
logger.error("before return vertices, " + errMsg.toString());
return vertices;
}
public List<ODocument> executeQuery(String sql, HashMap<String,Object> params,StringBuilder errMsg) {
List<ODocument> result = new ArrayList<ODocument>();
try {
db = getDatabase(errMsg);
if (!errMsg.toString().equals("")){
return null;
}
OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>(sql);
if (params.isEmpty()) {
result = db.command(query).execute();
} else {
result = db.command(query).execute(params);
}
} catch (Exception e) {
errMsg.append(e.getMessage());
//TODO: Add threaded error log saving mechanism
}
return result;
}
Due to index missing on table deadlock come, so check your all table which are involved in this operation and find out that indexes are present or not on column.
Refer link in which I have a same problem of deadlock.

Categories