How to use Order id in square-connect payment gateway in asp.net - asp.net-mvc

I use this code, this is working done payment when I remove OrderId: "21071" this, but I want to use OrderId: "21071" this is "21071" my website order id that customer place order from my website.
ChargeRequest body = new ChargeRequest(AmountMoney: amount, IdempotencyKey: uuid, CardNonce: nonce, BillingAddress: address, ShippingAddress: address, BuyerEmailAddress: txtEmail.Text, ReferenceId: "Booking #:" + bookingid, Note: bookingid, OrderId: "21071");
ChargeResponse response = transactionsApi.Charge(LocationId, body);
I face this error
Error calling Charge: {"errors":[{"category":"INVALID_REQUEST_ERROR","code":"NOT_FOUND","detail":"Resource not found.","field":"order_id"}]}
My error occurs when I use Orderid without Orderid it works fine, but I want to use Orderid

It seems like you're using your own Order ID there, instead of creating an Order using the Orders API first, and then referencing that Order ID in your Transaction.
You can find an example of how to use the Square Orders API here: https://developer.squareup.com/docs/orders-api/cookbook/link-orders-and-catalog-item

Related

Twilio "Unable to create Room" error comes up in JS API

For some reason I'm unable to create a room directly out of JS API like this:
TwillioVideo.connect(twillioToken, {name: 'my-name'})
.then(room => {
....
}, error => {
console.error('Unable to connect to Room: ' + error.message);
})
.connect method only works for me if the room was previously created, for instance:
I create the room first with C# like this:
public string CreateRoom(string roomName) {
TwilioClient.Init(_twilioSettings.AccountSid, _twilioSettings.AuthToken);
RoomResource room = RoomResource.Create(uniqueName: roomName);
return room.Sid;
}
then after it is created i can connect to it no problem.
So I'm forced to create a room in C# api and then use it in JS API. But i would rather avoid this step.
Also I did not find a way to determine if the room with the unique name already exist prior to calling RoomResource.Create(uniqueName: roomName) because if it does exist this method throws an exception. But i would rather return an SID of existing room in that case
Please advise
Twilio developer evangelist here.
In order to create rooms via the JS SDK, you need to have to have Client-side room creation enabled in your video settings in the Twilio console.

Stripe SCA checkout in ruby on rails

I am trying to update a monolithic rails stripe form to be SCA complaint, this is the documentation I am following https://stripe.com/docs/payments/checkout/migration#api-products-afterenter image description here
but is give in me error, invalid parameter, the error is in the picture, enter image description here
this is my code
const stripe = Stripe('pk_test_BqQVTnHd7yKaGgzUK9q8m8Ub00');
let checkoutButton = document.querySelector('#checkout-button');
checkoutButton.addEventListener('click', function () {
stripe.redirectToCheckout({
items: [{
// Define the product and SKU in the Dashboard first, and use the SKU
name: 'onex',
// ID in your client-side code.
id: 1,
parent: 'sku_Ft94t7sJmbJHlY',
sku: 'sku_123',
quantity: 1
}],
successUrl: 'https://www.example.com/success',
cancelUrl: 'https://www.example.com/cancel'
});
});
and I created a product in stripe dashboard
enter code here
enter image description here
According to Stripe's documentation, the only properties you can pass into the items list of stripe.redirectToCheckout are sku, plan, and quantity.
https://stripe.com/docs/stripe-js/reference#stripe-redirect-to-checkout
So in this case, the name, id, and parent properties are invalid. The "client-side" checkout integration is made to be pretty simplistic, where you create the SKU in the dashboard and simply include it in your JS.
If you need more control, I'd recommend looking at their server-side integration, which involves creating a Checkout Session.
https://stripe.com/docs/payments/checkout/server#create-checkout-session

Using the Browse option

I'm writing an application for Twinfield. I login to an account with 4 administrations in it. I would like to retrieve all information belonging to not payed invoices.
With the search opttion I get al open invoices for a certain office.
string[][] finderOptions = new string[2][];
switch (office)
{
case 0:
finderOptions[0] = new string[] { "office", "xxxx01-01" };
break;
case 1:
finderOptions[0] = new string[] { "office", "xxxx03-01" };
break;
}
finderOptions[1] = new string[] { "dim1", "1300" };
TwinfieldFinder.MessageOfErrorCodes[] errorCodes = xmlFinder.Search(hdrXml, "IVT", "*", 0, 1, 0, finderOptions, out findResult);
This works. But it retuns the invoicenumber and I also need the transaction number. Therefore I perform a Browse to find the traansaction number.
Maybe there is another way to find the complete transaction using the invoicenumber iso the transactionnumber?
The Browse call looks like this:
TwinfieldProcessXml.ProcessXmlSoapClient xmlClient = new
TwinfieldProcessXml.ProcessXmlSoapClient("ProcessXmlSoap", cluster + "/webservices/processxml.asmx?wsdl");
TwinfieldProcessXml.Header hdrXml2 = new TwinfieldProcessXml.Header();
hdrXml2.CompanyCode = finderOptions[0][1];
hdrXml2.AnyAttr = hdr.AnyAttr;
hdrXml2.SessionID = hdr.SessionID;
It doens't matter if I user the CompanyCode in the headers It alwasy return the informatie belonging to the first office: xxxx01-01.
When using the browse codes in Twinfield, make sure to do the SoapCall to select the right company, as documented there:
https://c3.twinfield.com/webservices/documentation/#/FAQ
Otherwise you will get the data back for the default company:
Q. When using the Browse Data functionality, in the response I get data from a different company. What is wrong?
A. In the browse data request there is no option to set the current company. Before sending the request, make sure the correct company is set by using the SelectCompany function. See also Web Services Authentication.
To get the open invoices the best way is to use the browse codes. Select code 100 and add a filter on the column matchstatus, here is an example:
https://gist.github.com/alexjeen/d4ef3295820dc98c7f0171e47294dbfe

Desire2Learn issue with calling API's

Am trying to use the valance api to call few methods. Am authenticating using https://apitesttool.desire2learnvalence.com from where am getting UserId & UserKey. Now am confused what should i pass in the x_a - x_d parameters for getting the organization info.
What ever i pass i get a 403 forbidden & incorrect token exception.
Some body please help. Am passing folling in the parameters.
x_a : Application ID
x_b : User ID( I got this from https://apitesttool.desire2learnvalence.com)
x_c : private String calculateParameterExpectation( String key, String httpMethod, String apiPath, long timestamp)
{
String unsignedResult = String.format("%s&%s&%s", httpMethod, apiPath, timestamp);
System.out.println(unsignedResult);
String signedResult = D2LSigner.getBase64HashString(key, unsignedResult);
return signedResult;
} Where key is the App Key
x_d : private String calculateParameterExpectation(
String key, String httpMethod, String apiPath, long timestamp) {
String unsignedResult = String.format("%s&%s&%s", httpMethod, apiPath, timestamp);
System.out.println(unsignedResult);
String signedResult = D2LSigner.getBase64HashString(key, unsignedResult);
return signedResult;
} Where key is the User Signature that i got from https://apitesttool.desire2learnvalence.com
Am not sure what is done wrong.
Please note that each back-end service generates a unique UserID/Key pair to go with each user and each application ID, upon request by a call from that application ID.
This explicitly means that User ID/Key pairs are not transferrable from one application to another. Nor are they transferrable from one back-end service to another -- every API-using application should request its own UserID/Key pair for making calls on behalf of each distinct user. Even if you used your App ID/Key when using the api-test tool, unless you pointed the tool at the same back-end service you're actually making the API calls against, you won't get back a UserID/Key pair you can use for later making the API calls (against another service).
Please also note that the signing mechanism requires that you use the upper-case version of the http-method string (thus GET, not get), and it requires that you use the lower-case version of the api path string (thus /d2l/auth/api/token, not /D2L/AUTH/API/TOKEN). If you're pointing the api-test tool at the same LMS you're wanting to make API calls against, and you're using the same App ID/Key pair with the api-test tool as you're using in your production code, then I would seek to make sure that you're formatting your base string exactly right for signing.
I would also encourage you to make fuller use D2L's own client SDK libraries for doing the app/user context management and signing, rather than just using the raw signing call from within the library.

MVC Paypal Adaptive Payments

Here's what I'm designing a site where multiple shops my be able to offer their producs to sale. Every seller will have a virtual store on my site. I'm using paypal for purchase operations. I've considered to allow customers to use credit card without having a paypal account, and I'm trying to use Adaptive payments flow to allow "buy as guest" flow. I'm trying to use paypal default flow (not the rest api) since I don't want to be worried about handling credit card data and having to design my site as PCI compliant.
So with this escenario here's what I'm using:
From this site https://developer.paypal.com/webapps/developer/docs/classic/adaptive-payments/integration-guide/APIntro/ I'm trying to implement the payment flow specified on the section
Setting Up Web Pages to Invoke the Embedded Payment Flow Using a Lightbox
Since this payment flow requires a pay key to be generated, I'm using the code found on this link:
https://github.com/paypal/rest-api-sdk-dotnet/tree/master/Samples/RestApiSample
-So on my MVC I have a page that generates the order, and it calls a Helper methods to get the paykey. Here's the most relevant one:
public static string GetPayKey(DummyPurchase purchase)
{
ReceiverList receiverList = new ReceiverList();
receiverList.receiver = new List<Receiver>();
//(Required) Amount to be paid to the receiver
string[] amt = new string[1] { purchase.TotalPrice.ToString() };
// Receiver's email address. This address can be unregistered with paypal.com.
// If so, a receiver cannot claim the payment until a PayPal account is linked
// to the email address. The PayRequest must pass either an email address or a phone number.
// Maximum length: 127 characters
string[] receiverEmail = new string[1] { purchase.StoreId.ToString() };
string cancelUrl = ConfigurationHelper<string>.GetKeyValue(Constants.PAYPAL_CANCEL_URL);
string returnUrl = ConfigurationHelper<string>.GetKeyValue(Constants.PAYPAL_RETURN_URL);
string currency = ConfigurationHelper<string>.GetKeyValue(Constants.PAYPAL_CURRENCY_CODE);
//Generate Receivers list
for (int i = 0; i < amt.Length; i++)
{
Receiver rec = new Receiver(Convert.ToDecimal(amt[i]));
if (receiverEmail[i] != string.Empty)
{
rec.email = receiverEmail[i];
}
receiverList.receiver.Add(rec);
}
PayRequest request = new PayRequest(new RequestEnvelope("en_US"), "PAY",
cancelUrl, currency,
receiverList, returnUrl);
//call the service
AdaptivePaymentsService service = null;
PayResponse response = null;
try
{
// (https://github.com/paypal/sdk-core-dotnet/wiki/SDK-Configuration-Parameters)
Dictionary<string, string> configurationMap = GetAcctAndConfig();
// Creating service wrapper object to make an API call and loading
// configuration map for your credentials and endpoint
service = new AdaptivePaymentsService(configurationMap);
response = service.Pay(request);
}
catch (Exception ex)
{
Elmah.ErrorLog.GetDefault(null).Log(new Elmah.Error(ex));
return "";
}
Dictionary<string, string> responseValues = new Dictionary<string, string>();
string redirectUrl = null;
if (!(response.responseEnvelope.ack == AckCode.FAILURE) &&
!(response.responseEnvelope.ack == AckCode.FAILUREWITHWARNING))
{
return response.payKey;
}
return "";
}
-After I get this key, I get the html from another view that has the form as the API guide specifies, having the paykey string as the model for this view.
#model string
<h2>ConfirmCheckout</h2>
<script src="https://www.paypalobjects.com/js/external/dg.js">
</script>
<form action="https://www.paypal.com/webapps/adaptivepayment/flow/pay"
target="PPDGFrame">
<input id="type" type="hidden" name="expType" value="light">
<input id="paykey" type="hidden" name="paykey" value="#Model">
<input type="submit" id="submitBtn" value="Pay with PayPal">
</form>
-After the view is rendered, I call the javascript code to start the flow:
var dgFlow = new PAYPAL.apps.DGFlow({ trigger: 'submitBtn' });
-The flow works perfectly and I get a valid pay key rendered on this form. But when I click this button (submit button on form with paykey) I get 2 different errors. This is the most frequent one:
This transaction has already been approved. Please visit your PayPal Account Overview to see the details.
-But sometimes I get a "Your payment session has expired" error.
I have 2 questions:
Does someone know how to fix those errors?
I'm using clasic API since guest payment flow for adaptive payments require a PayKey to start the flow (in order to avoid security and PCI complience matters). I did not found a method on the Paypal REST API that could get the same PayKey. Is there any method to get those keys?
Thanks a lot
Well this is really embarrasing... but the real issue was the url on the post action of the form. I had
<form action="https://www.paypal.com/webapps/adaptivepayment/flow/pay" target="PPDGFrame">
Which is production link. And I'm not going live yet, I'm using paypal api credentials for a sanbox account, so the real form action should be:
<form action="https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay" target="PPDGFrame">
Duh!. Well hope that this could help another person with same kind of errors.
Thanks a lot #Andrew Angell
It sounds like you're sending a Preapproval key with your Pay request. When you do that, there's no redirect to PayPal required. That's the whole point...you've already got approval via the Preapproval Key, so when you submit a Pay request with a preapproval key included the payment will be made immediatly (as long as the preapproval profile is still valid.)
As such, when you're doing the redirect, it's telling you exactly what happened...the transaction was already processed. Again, no need for a redirect.
The whole point is to be able to trigger payments using the preapproval profile within your application at any time you need to with any redirect or further approval. Once you have that preapproval key you can trigger payments any way you want to. For example, you might want to charge somebody per use and trigger a payment when they log in to your website, but you don't want them to have to approve the payment every time. The payment could happen in the background via the Pay API with the preapproval key included but the user would not be interrupted at all.
Hope that helps.

Resources