I am currently working with PayPal's Merchant SDK and I am wondering how can I check a payment status? That's especially useful for pending payment or delayed. All I keep in database is the Payer ID.
I want a method to check the payment status so that I can proceed with the payment once is it approved, or canceled, using PayPal's Merchant SDK.
Here's an example:
GetExpressCheckoutDetailsRequestType req = new GetExpressCheckoutDetailsRequestType
{
Token = token
};
GetExpressCheckoutDetailsReq detailsReq = new GetExpressCheckoutDetailsReq
{
GetExpressCheckoutDetailsRequest = req
};
GetExpressCheckoutDetailsResponseType response = service.GetExpressCheckoutDetails(detailsReq);
However in this current example I do not have the token, which is a value returned when I first create the payment, and I am not sure if I will get the payment status.
What should I do to achieve what I want? Or do I need to proceed with another SDK, or the REST Api?
Try the getAck() method per this documentation
It will return an AckCodeType (which can be one of the values here). You'll want to proceed if that value is Success and potentially SuccessWithWarning.
Related
I've read a lot of documentation on "why" my Stripe payment intents are left in a status of "The Customer has not entered a payment method" and that "We recommend that you explicitly provide the payment_method going forward" however I can't tell how do that (provide the payment_method).
When I initialise the Payment Intent object I have "AutomaticPaymentMethods" enabled. I only have 1 payment method enabled in my Stripe Dashboard (cards).
(Also, I'm using Blazor with JS interop for this - if that is relevant...)
string customerId = await getCustomer(); // fetch existing customer from Stripe API based on current user or create a new one
Stripe.PaymentMethodService pms = new PaymentMethodService();
Stripe.PaymentIntentCreateOptions options = new PaymentIntentCreateOptions
{
Amount = p.UnitAmount,
Currency = p.Currency,
Customer = customerId,
ReceiptEmail = "test#malinator.com",
Description = "Test Purchase",
StatementDescriptor = "Test Purchase",
AutomaticPaymentMethods = new PaymentIntentAutomaticPaymentMethodsOptions
{
Enabled = true,
},
};
Stripe.PaymentIntentService pis = new Stripe.PaymentIntentService();
Stripe.PaymentIntent pi = pis.Create(options);
return pi;
The Payment Method is null on the resulting Payment Intent object.
It is still null after the payment details have been completed in the "payment-element" on my HTML form.
Is the payment_method something I can set up as the Payment Intent object is created (as I only wish to use "cards" at the moment anyway), or is it something I need to set in the confirm_payment JS call? (Either way, how to I obtain that Payment Method?)
Your code creates a PaymentIntent server-side for say $10 USD. This represents the "state machine" of an overall payment for the customer. They might never pay, or they might try to pay once and get a decline or a success, or they might get declined, try another card and see a success. Each "payment attempt" is represented in the API as a Charge object and the corresponding payment method details associated with that are represented as a PaymentMethod.
Now all of that "payment attempt" happens client-side where you collect payment method details and you use those to "confirm the PaymentIntent".
You mentioned you are using PaymentElement which is Stripe's newer UI library component to collect payment method details and accept a payment client-side. Since you only accept card payments, the PaymentElement would get initialized with your PaymentIntent's client_secret and render the card form to collect those card details.
What you need to do here is have a button to "pay" and when it's clicked, your Javascript code should call the confirmPayment() method from Stripe.js. Doing that will use the card details entered by the customer and attempt to confirm the PaymentIntent that is for a specific amount and currency. This payment might succeed, in which case the customer is redirected to your return_url, or it might be declined in which case the promise completes with error details you can handle to surface an error.
What you need to do here is look into your client-side code, ensure that you call confirmPayment() as expected and debug the response you get back to help narrow it down.
After the PaymentIntent is confirmed successfully and has status: 'succeeded' then it will have payment_method: 'pm_123' that is the id of the PaymentMethod object associated with the successful confirmation. All the information about that card would be on the successful Charge object associated with it inside payment_method_details.
I am looking into publishing some service status updates on Twitter using Tweetinvi, which seems like a good library for doing that sort of thing, but I am just starting out looking into this so using it is not set in stone.
However, one thing my research has not yielded yet, is an obvious way to handle Twitter authentication in what is essentially a headless service. I have created an app with Twitter, so I have my consumer key and secret, and I can do the "app only" auth to request user info, get their followers etc., but of course I have no right to publish tweets.
So my ambition is (once this is out of beta) to create a proper twitter account, somehow have the service authenticate towards that account, and then publish status updates from the general service at defined intervals. It is a fairly simple idea.
Of course, I can do something like the PIN based authentication mentioned here:
https://github.com/linvi/tweetinvi/wiki/Authentication
I can run that manually, get the PIN code, and proceed with the workflow. But will this require reauthentication at regular intervals, or will it basically be valid "forever"? I am looking for a way to make this as automatic as possible, and having to redo the auth every x hours is a huge dent in this dream, if not a showstopper.
Of course I will have the password for the twitter account used to publish statuses, but I don't see a way to do a good old fashioned login without manual user intervention - what options do I have?
This behavior is by design. Twitter uses OAuth, which is a protocol with the purpose of allowing a user to authorize an application. This is good for the user because otherwise, you or anyone else can perform actions on their behalf without them knowing.
With that in mind, the only way to do this is to have the user explicitly authorize your app. Here's an example of how to do this with LINQ to Twitter, which I wrote, using ASP.NET MVC. When the user visit's your page, you can have a button that re-directs them to the OAuthController below to the BeginAsync action.
using System;
using System.Configuration;
using System.Linq;
using System.Threading.Tasks;
using System.Web.Mvc;
using LinqToTwitter;
namespace MvcDemo.Controllers
{
public class OAuthController : AsyncController
{
public ActionResult Index()
{
return View();
}
public async Task<ActionResult> BeginAsync()
{
//var auth = new MvcSignInAuthorizer
var auth = new MvcAuthorizer
{
CredentialStore = new SessionStateCredentialStore
{
ConsumerKey = ConfigurationManager.AppSettings["consumerKey"],
ConsumerSecret = ConfigurationManager.AppSettings["consumerSecret"]
}
};
string twitterCallbackUrl = Request.Url.ToString().Replace("Begin", "Complete");
return await auth.BeginAuthorizationAsync(new Uri(twitterCallbackUrl));
}
public async Task<ActionResult> CompleteAsync()
{
var auth = new MvcAuthorizer
{
CredentialStore = new SessionStateCredentialStore()
};
await auth.CompleteAuthorizeAsync(Request.Url);
// This is how you access credentials after authorization.
// The oauthToken and oauthTokenSecret do not expire.
// You can use the userID to associate the credentials with the user.
// You can save credentials any way you want - database,
// isolated storage, etc. - it's up to you.
// You can retrieve and load all 4 credentials on subsequent
// queries to avoid the need to re-authorize.
// When you've loaded all 4 credentials, LINQ to Twitter will let
// you make queries without re-authorizing.
//
//var credentials = auth.CredentialStore;
//string oauthToken = credentials.OAuthToken;
//string oauthTokenSecret = credentials.OAuthTokenSecret;
//string screenName = credentials.ScreenName;
//ulong userID = credentials.UserID;
//
return RedirectToAction("Index", "Home");
}
}
}
After the user authorizes your application, Twitter redirects them back to the CompleteAsync method. Notice the comments on how to extract values from the auth.CredentialStore. Save those in your DB and then retrieve them in your service to make calls on the user's behalf.
Those credentials don't change, but the user can possibly de-authorize your application at some time in the future - at which time you'll need to get them to authorize again. You can get the entire sample code at the LINQ to Twitter ASP.NET Samples page.
I have a Twilio number and I understood that in order to do those 4 actions(Call, Hang up, put onhold and unhold calls) I need to create a conference call, but I don't understand how I add my Twilio number to the conference and how do I add another number of a mobile of a client. For example, if my Twilio number is " +9728888888" and the customer's I want to call to mobile number is "+9725555555" – I want code examples of :
1. Calling the customer(from Twilio number " +9728888888" to mobile number "+9725555555")
2. Hold the call
3. UnHold the cold
4. Hangout the call.
I'm using Twilio NuGet on web api project. Can you give me the code examples , considering the numbers I gave(Twilio and mobile) for all of those four scenarios above? I would really appreciate it.
BTW, I saw the code example on their site:
using Twilio.TwiML;
class Example
{
static void Main()
{
var response = new VoiceResponse();
var dial = new Dial();
dial.Conference("moderated-conference-room",
startConferenceOnEnter: false);
response.Dial(dial);
System.Console.WriteLine(response.ToString());
}
}
but it doesn't acknowledge the Twilio or the mobile phone or even the Twilio authentication so I'm not sure how can it work..
Twilio developer evangelist here.
If you want to make a call from your Twilio number to a end user and put both your agent and the user into a conference call then this is the way that I would do it. I am not, however, a C# developer, so while I'll try to give code samples I'm not experienced in .NET web api projects.
You say that you are using the Twilio package from Nuget, that's a good start.
First up, you need to generate a call to your agent and place them in the conference call to wait for the user. To do this, you would use the Twilio REST API to place the call. That code looks a bit like this
const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
const string authToken = "your_auth_token";
TwilioClient.Init(accountSid, authToken);
var to = new PhoneNumber("AGENT_PHONE_NUMBER");
var from = new PhoneNumber("+9728888888");
var call = CallResource.Create(
to,
from,
url: new Uri("http://example.com/conference")
);
When this call connects with the agent's number Twilio will make a request to the URL that is sent to the API. Your application needs to respond to tell Twilio what to do with the call. In this case, we should put the agent into a <Conference> to wait for the user. Within this action we also need to generate a call to the user.
public IHttpActionResult Conference()
{
// make the call to the user
var to = new PhoneNumber("+9725555555");
var from = new PhoneNumber("+9728888888");
var call = CallResource.Create(
to,
from,
url: new Uri("http://example.com/user_conference")
);
// return the TwiML
var response = new VoiceResponse();
var dial = new Dial();
dial.Conference("Conference", endConferenceOnExit: true);
response.Dial(dial);
Ok(response.ToString());
}
Note: I've set the agent side of this conference to endConferenceOnExit: true. This means that when the agent hangs up, the conference call will end for all participants.
Now, Twilio will make the call to the user and when that connects ask the new URL what to do with the call. This time you just need to respond with the TwiML to connect to the same conference. I'll leave that for you to deal with.
Finally, to put participants on hold you need to use the REST API again. You need to get the conference SID and the SID of the participant you want to put on hold. Since you will be putting the user on hold from your agent, you get both of these SIDs in the second webhook callback to your application.
With the conference and call SID, make a POST request like this:
const string conferenceSid = "CONFERENCE_SID";
const string callSid = "CALL_SID";
ParticipantResource.Update(
conferenceSid,
callSid,
hold: true,
holdUrl: new Uri("http://example.com/hold")
);
You can also provide a hold URL which can provide music while the user waits. For more information, check the participant resource documentation. Unholding the user is the same process, but you set hold to false.
Let me know if this gets you on the way to creating this feature.
Im using the c# sdk to do a direct payment to paypal.
Everything works great, however im not getting the transactionId because the sdk's "Payment" object does not have a transactionId nor does the http response.
the code is very simple.
Payment pymnt = new Payment();
pymnt.intent = "sale";
pymnt.payer = payr;
pymnt.transactions = transactions;
Payment createdPayment = pymnt.Create(apiContext);
Pymnt Create method, creates and Executes the payment and retrieves back the properties by converting them from json.
I am getting back payid.I checked documentation but couldnt find any on how to get transactionId via payid.
Another part of my application that is created with paypal standard gets the paypal transaction id via the "txn_id" query parameter in the IPN method and saved it in the database.
Thus we need save the transactionid in the database to be consistent.
Please help.
(A similar question was asked on GitHub.)
The transaction ID for a payment can be found via the related_resources property of each transaction associated with a payment.
For example, if you make a sale payment, the transaction ID can be retrieved via the following:
var payment = Payment.Get(apiContext, "PAY-89W644977H834061FKTDRCCY");
var transactionId = payment.transactions[0].related_resources[0].sale.id;
I use below code for Paypal Rest API to Store Credit Card Information
String AccessToken = "";
PaypalAccessToken pat = new PaypalAccessToken();
AccessToken = pat.GetPaypalAccessToken();
PayPal.Api.Payments.Address add = new PayPal.Api.Payments.Address();
add.city = TextBoxCity.Text;
add.line1 = TextBoxAddress.Text;
add.phone = TextBoxPhoneNumber.Text;
add.postal_code = TextBoxZipcode.Text;
add.state = DropDownState.SelectedValue;
PayPal.Api.Payments.CreditCard cc = new PayPal.Api.Payments.CreditCard();
cc.number = TextBoxCreditCardNumber.Text;
cc.expire_month = Convert.ToInt16(TextBoxExpiryMonth.Text);
cc.expire_year = Convert.ToInt16(TextBoxExpiryYear.Text);
cc.cvv2 = TextBoxCVVNumber.Text;
cc.type = DropDownCreditCardType.SelectedValue;
//cc.billing_address = add;
PayPal.Api.Payments.CreditCard ResultCC = cc.Create(AccessToken);
This Code working good with Demo Credentials but When I try to use same with Live Credentials, It is giving me error : 401 Unauthorized. I can still get token in live credentials but I could not store credit card.
PayPal's REST API's are available globally as of the 31st of July 2013.
However, this applies only to PayPal payments. That is, setting the payment_method to paypal in the JSON payload and redirecting the buyer to PayPal.
If you want to process credit card payments, this is currently only supported in the US, UK or Canada.
You will need to enable this capability for your app via https://developer.paypal.com/ > Applications.
Note: Enabling card payments for live transactions requires a review of your account.
If you try to process card payments in live, with an account that's not enabled for it, you will get a HTTP 401 in the response from the /payment resource.
Have you updated your endpoints to use the live endpoints?
It was something wrong with Paypal Rest ApI because its still in Beta version . They fixed it for me.