In order to test a MercadoPago integration the documentation tells that you need at least two test users: a seller and a buyer. It also explains how to create them but not how to use them.
I suppose the seller info should be hard-coded somewhere in the server side. Where? Is there a field in the preference data to specify the seller user?
I know there is a payer field and I used it to specify the buyer. But what about the seller?
I already tried filling the client_id and collector_id fields of the preference data with the test-user id with no avail.
MP mp = new MP("???", "????");
JSONObject preference = mp.createPreference("{items:[...], client_id: 262046207}");
Where 262046207 is the test-user id of one of the two test users I generated.
When the user submits a payment he gets this error message: "Una de las partes es un usuario de prueba."
Steps:
Create two test users: one for acting as the buyer, and the other for acting as the seller. Here are the instructions to create a test user.
Log out if you are already logged in.
Log in to MercadoPago with the seller test user using the e-mail and password you obtained in step 1. If the login dialog asks for your password before the e-mail, click the link "no soy ..." which is below the login dialog.
Then go to this link to obtain the credential you need to authenticate programmatically from the server.
Then go to this link to configure the URL where your server will listen to the MercadoPago notifications. If you have a router, don't forget to open the port.
At the time of testing a purchase, log in to MercadoPago with the e-mail and password of the buyer test user.
To pay with credit cards, use any of these cards numbers. The other fields can be filled with anything, but the card holder's name should start with any of the prefixes enumerated at the bottom of the mentioned page.
Related
I'm working with telegram bot and i have this method to get user messages.
I need to find a way to get a link to the user who send this message
I saw there are this method, but i dont know how to connect them to a "link" to a profile
#Override
public void onUpdateReceived(Update update) {
update.getMessage().getFrom();
// i have: getFirstName(), getLastName() - not helping
// i have also getId() - but its a number how do i convert it to a link to telegram profile ?
}
Having username is optional on Telegram, setting it up means other people will be able to contact the user without knowing their phone number. Only users that chose their username in Telegram settings have a profile link, and the link is of the form https://t.me/<username>.
For ordinary messages, you can get the username via update.getMessage().getFrom().getUsername() and use it to create profile links, however, note that for many users this value will be empty (meaning they don't have a profile link).
Also, if you keep database of chat IDs, you can get usernames of the users via getChat Telegram API call. This can be useful because while usernames can be changed by the user any time (meaning their profile link will also change), chat ID of the user is constant over time and the getChat method will always provide you with the most recent information.
I want to create a unique user name for my users, but this will be not system generated. Users can choose his/her user name.
DB
MongoDB
Ex
Github user name
Current process
sign-up
get a verification link on the email
go to the link, like example.com/verify?token=xyz...
On verify page user can enter a user name, that user name must be unique across the DB.I don't want to keep duplicate user names.
Many websites have implemented this feature, like Github, GitLab, etc. But, I have explored some web about implementing this feature and I didn't get the desired result.
After entering the user name in step 3, the browser will make a POST request to the server.
Server will then check the DB that if this user name already exists or not, if this already exists then throw an error or process the user name otherwise.
This is working on my local PC, but I am not sure whether this will work when multiple users make a request with the same username within a time interval. Then, in this case, there may be some duplicates in DB.
case
There are two users A and B wants to create their user name on the system at the same time.
both are requesting the same user name
A: make the request for the user name u1
Server: check for A's user name is present or not in DB
B: make the request for user name u1
Server: A's user name is not present, save u1 as A's user name
Server: B's user name is not present, save u1 as B's user name
You can see, in the end, both users's haveing the same user name.
Is there any way to avoid this??
The solution depends on your Database. If you are using SQL database, you can just add UNIQUE constrain to the field, so the database will enforce the uniqueness of an attribute value in the table. The first row will be inserted while another row will fail to insert with an error that the field is not unique.
Speaking of MongoDB, you also have a unique index.
-> As the above answer suggested have a unique constraint on DB for user name and if the insert didn't happen send an error response stating username already taken also
-> We do not need to wait until the user submits the request, as the user types in the user name, call an API to check if the username already exists, and while calling this cancel the previous request which we haven't got a response back. For example when the user types vi you send a request and it is still in progress but the user has typed vig now before sending the new request with 'vig' data, cancel the previous request. ( Ans simultaneously show the status whether taken or not as you get the responses )
This improves the user experience.
-> The cancelling of the requests can be done using cancel tokens in Axios, if you are going with Axios.
For MongoDB:
If you can create an additional unique index based on a combination of fields, can't you use an additional dummy field ( which has the same data for all users), so now your username would stay unique? (I haven't used MongoDB a lot to be sure of this. )
OR this is mentioned in the Mongo DB documentation , create a proxy collection to maintain this username as a unique key, following the first segment in the below document
https://docs.mongodb.com/manual/tutorial/unique-constraints-on-arbitrary-fields/
I am trying to implement the scenario in which a new user has been created in my application by Admin.
1st step will be
user has allotted by a temporary password
and receives the email with an activation link
User will just by clicking on that link taken to the create new password page , he creates his new password and thats it.
Now my query is how will the application knows that which user is this ,just by clicking that activation link in his email
Activation links carry a long token, such as activate.jsp?tok=98357627272357852786276258763427934579342579342793426734279. This token can be randomly selected, and stored in a database. When the page is loaded, the token is looked up, and the correct user gets authenticated. The token may then be deleted from the database.
I'm developing a website with using struts2 and hibernate as back end. In many sites after you sign-up, a link will be sent to your email and after clicking on that the registration is complete. I want this feature on my webstie, but I don't have any idea how to do this and how is this working? i needsome example to do this....
I have never messed around with struts, but basically what you could do would be to send an email with a link which directs to a specific page. When a user signs up to your website you could save, amongst other things, the email address of the user, the time stamp of the registration and also a key (could be the hash of the email and password, for instance).
You then construct the link and include the email and key in the query string. Once that the user clicks the link, in your page you make a check to see that the user is still within some time frame (optional) and that the email given matches the given key (which you have stored in the database).
If the email and key match, then activate the account.
This is broad question but I am answering based on verification
1. You need a signup page with form example /signup.jsp
2. After basic fields and email validation, generate a code xyzcode for this email,
3. Send email to user email, using a mail server with a link to your link validation page like
/validate.jsp?code=xyzcode (mail server setup and sending email is beyond the scope of the answer)
4. On validate.jsp check code and validate any email with this code otherwise give respective error message.
There are multiple approaches but I am suggesting one which will be easy and as per standard..
In user table add extra column as Status [which can take two values either inactive or Active]
create one more table(emailauthentication) where columns will be (key,emaiId)..
Now what u have to do is after user click submit with registration data...gnerate a dynamic key..could be timestamp+emailId(or anything dynamic and unique) and create record in user table with status as inactive and create record in emailauthentication table with this generated key and emaiId..now after record is created generate a URL which could be like
<a href="doAuthenticationForUser?authenticationId='dynamicKey'"/>Click to authenticate</a>
Now when user clicks this URL then in the action class or Service for this authenticationId find the emailId and make the column status as active..
It is true it is quite big to answer the question.
I knew one link which has the best answer given by BalusC
Here is link:better answer.
I have implemented in my project. I hope this link will help others.
Thanks for reading.
I am registering user with email address . but i want to send the user a confirmation link where if they click then their email address gets confirmed
I am using java spring MVC hibernate mysql
Among other tools you can use "java mail" package to send emails direclty from your application. Here's the link to API docs Java Mail API
So the scenario could be like the following:
User account is created. It's in unconfirmed state now;
You generate a unique confirmation ID to your applicaiton. The easiest way is to use java.util.UUID.randomUUID().toString(). UUID is a random globally unique value.;
You store the ID (e.g. 0123)+account to the database for future use;
Send the URL+ID (http://yourapp.com/confirm?id=0123) as an email using javamail to the user;
Do not show the ID in browser now;
The user checks inbox and see your letter;
The user clicks the link and request is sent to your site confirmaion servlet;
Confirmation servlet will search for the account associated with the specified confirmation id;
Confirmaion servlet set account to "confirmed state" as obvously the user has access to the specified mail box
Use Java Mail Api to create a e-mail with confirmation. Also, you need to generate unique id to confirm the user - this info can be stored in db. After the moment user clicks on your confirmation link you should set user in 'Confirmed' state.