PaymentRequest API not defined - javascript

I am trying to run an example of the Payment request API as shown on https://www.youtube.com/watch?v=yelPlCVZLEE .
I have followed the process as they describe and i Have also run the following code:
function go() {
console.log('Pay');
var request = new PaymentRequest([{
supportedMethods:['urn:payment:visa','urn:payment:mc','urn:payment:amex']
}],
{
total: {
label: "Total due",
amount: { currencyCode: "USD", value: "60.00" }, // US$60.00
}
}
);
request.show()
.then(function(response) {
// process transaction response here
return response.complete(true);
})
.then(function() {
alert("Buy!");
})
.catch(function(e) {
alert(e.name);
});
}
and I get the following error: Uncaught ReferenceError: PaymentRequest is not defined.
If I run the test from :
http://github.adrianba.net/paymentrequest-demo/tests/payment-tests.html
It's says it's defined.
What I am doing wrong?

The site you linked, http://github.adrianba.net/paymentrequest-demo/tests/payment-tests.html, pulls in a file:
<script src="../lib/paymentrequest.js"></script>
which defines its own implementation of PaymentRequest:
function PaymentRequest(methodData,details,options) {
// Constructor code
if(!Array.isArray(methodData) || methodData.length===0) throw new TypeError("methodData must be a non-empty sequence of PaymentMethodData");
methodData.forEach(d => {
...
http://github.adrianba.net/paymentrequest-demo/lib/paymentrequest.js
To get PaymentRequest in Chrome, you have to enable it in chrome://flags/#enable-experimental-web-platform-features

Related

Getting "Uncaught TypeError: Illegal invocation throws at" in salesforce community when using AutoNumeric,js

When i run below js in separate LWC, it works fine. If i try to include this code in another lightning web component it is throwing error as soon as i click on the input box or any button. If i redeploy the previous code then also the error is coming in that particular community. Rest of the communities working fine.
jsInitialized = false;
#track currencyValue = '';
handleCurrencyChange(event) {
var options = {
currencySymbol: "$",
decimalPlaces: 0
};
this.currencyValue = AutoNumeric.format(event.target.value, options);
}
renderedCallback() {
if (this.jsInitialized) {
return;
}
this.jsInitialized = true;
Promise.all([
loadScript(this, libs + '/libs/autonumeric.min.js'),
loadScript(this, libs + '/libs/libphonenumber-max.js')
])
.then(() => {
})
.catch(error => {
this.dispatchEvent(
new ShowToastEvent({
title: 'Error loading Scripts',
message: error.message,
variant: 'error'
})
);
});
}

How to execute `Rollup` request using `Xrm.WebApi.execute` method in MS CRM using JS

There is a nice example how Rollup function could be called via MS CRM WebApi here.
But it covers general access to CRM WebApi. Although in most recent versions new JS namespace Xrm.WebApi was introduced. Which provides more straightforward way to access that endpoint.
Method Xrm.WebApi.execute should be able to execute Rollup request, as it is able to execute WhoAmI. But I'm struggling to figure out correct values of parameters to make this execution happen.
Here is my code:
var RollupRequest = function(entityType, id, query) {
this.Target = { entityType: entityType, id: id };
this.RollupType = "Related";
this.Query = {
Query: query
};
};
RollupRequest.prototype.getMetadata = function() {
return {
boundParameter: null,
parameterTypes: {
Target: {
typeName: "Microsoft.Xrm.Sdk.EntityReference",
structuralProperty: 5
},
RollupType: {
typeName: "Microsoft.Dynamics.CRM.RollupType",
structuralProperty: 3
},
Query: {
typeName: "Microsoft.Xrm.Sdk.Query.FetchExpression",
structuralProperty: 5
}
},
operationType: 1, // This is a function. Use '0' for actions and '2' for CRUD
operationName: "Rollup"
};
};
var request = new RollupRequest(
"contact",
"0473FD41-C744-E911-A822-000D3A2AA2C5",
"<fetch><entity name='activitypointer'></entity></fetch>"
);
Xrm.WebApi.execute(request).then(
function(data) {
console.log("Success: ", data);
},
function(error) {
console.log("Failure: ", error);
}
);
The code generates following URL:
/api/data/v9.0/Rollup(Target=#Target,RollupType=#RollupType,Query=#Query)?#Target={"#odata.id":"contacts(0473FD41-C744-E911-A822-000D3A2AA2C5)"}&#RollupType=&#Query={"Query":"<fetch><entity name='activitypointer'></entity></fetch>"}
and the error: "Expression expected at position 0 in ''."
Which, seems to be, indicates that RollupType was not set correctly, because indeed in URL RollupType is missing.
I assume there are more than one potential error, because I'm using FetchXML as query expression. But meanwhile is it possible indicate what should be changed to generate proper URL at least for RollupType property?

Updating Stripe accounts returns "Error: Stripe: "id" must be a string, but got: object"

I am trying to update a Stripe account to add an external account token to be charged later as shown in the example here.
var stripe = require("stripe")("sk_test_xxxxxxxxxxxxx"),
knex = require("knex")(config);
router.post("/paymentcardinfo",middleware.isLoggedIn,function(req,res){
knex("users.stripe").select("stripe_id_key")
.then((stripeID) => {
stripeID = stripeID[0].stripe_id_key;
console.log("My Stripe ID: "stripeID);
console.log("stripeID var type:", typeof stripeID);
stripe.accounts.update({
stripeID,
external_account: req.body.stripeToken,
}, function(err,acct) {
if(err){
console.log(err);
} else {
console.log("SUCCESS ********",acct);
// asynchronously called
}})
})
.catch((e) => {
console.log(e);
res.redirect("/paymentcardinfo")
});
});
Which returns the following
My Stripe ID: acct_xxxxxxxxxxxxx
stripeID var type: string
[Error: Stripe: "id" must be a string, but got: object (on API request to `POST /accounts/{id}`)]
where acct_xxxxxxxxxxx is the user's stored account ID. Based on the first console.log value, it would appear that stripeID is a string and not an object, which makes me unsure of how to proceed with this error.
Although the documentation specifies
stripe.accounts.update({
{CONNECTED_STRIPE_ACCOUNT_ID},
metadata: {internal_id: 42},
}).then(function(acct) {
// asynchronously called
});`
The following worked for me
stripe.accounts.update(
CONNECTED_STRIPE_ACCOUNT_ID,
{
metadata: {internal_id:42},
}
).then((account) => {
// response to successful action

ignored children tests in Frisby JS with jasmine-node

I use Frisy with jasmine-node to test an Meteor API.
I want to test the remove of a discussion in a chat App. For this, I need to create a new discussion in chat and add a message in the discussion.
I noticed that my test fail if I put it after the second .then() method. It fails also after the third .then(). However, it works correctly after the first .then() method.
An example code with explicit failed test expect(false).toBe(true);:
var frisby = require('frisby');
describe("chat update", function() {
it("message added", function(done) {
frisby.post('http://localhost:3000/api/chat', {
name: "remove"
})
.then(function (res) {
let id = res._body.id;
expect(false).toBe(true); // (1) it fails the test
frisby.post('http://localhost:3000/api/chat/'+id+'/addmessage',
{
auteur: "Samuel",
message: "My message"
}
)
.then(function (res) {
expect(false).toBe(true); // (2) Without (1) it's ignored by frisby
frisby.post('http://localhost:3000/api/chat/remove',
{id: id}
)
.then(function (res) {
expect(false).toBe(true); // (3) Without (1) it's ignored by frisby
})
});
})
.done(done);
})
});
If I run the test, it will fail thanks to expect(false).toBe(true); // (1) it fails the test line.
If I remove this line, the test will run and jasmine valid it as right.
Do you know a way to don't ignore the (2) and (3) tests ?
Finaly, I found the solution.
It's because I forgot to return all frisby action (except the first one) like in the following code:
var frisby = require('frisby');
describe("chat update", function() {
it("message added", function(done) {
frisby.post('http://localhost:3000/api/chat', {
name: "remove"
})
.then(function (res) {
let id = res._body.id;
return frisby.post('http://localhost:3000/api/chat/'+id+'/addmessage',
{
auteur: "Samuel",
message: "My message"
}
)
.then(function (res) {
return frisby.post('http://localhost:3000/api/chat/remove',
{id: id}
)
.then(function (res) {
expect(false).toBe(true); // Will fail the test
})
});
})
.done(done);
})
});
You may notice the return operators before frisby.post().
I hope it will help !

PayPal Express Checkout, error when supplying input_fields

I'm using PayPal Express Checkout from JavaScript.
This is the code I have and works (I see the PayPal button, I can click it, and the payment window opens fine):
<div id="paypal-button"></div>
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
<script>
paypal.Button.render({
env: 'sandbox',
client: {
sandbox: 'xxxxxx',
production: 'yyyyyy'
},
payment: function () {
var env = this.props.env;
var client = this.props.client;
return paypal.rest.payment.create(env, client, {
transactions: [
{
amount: { total: '1.00', currency: 'USD' }
}
]
});
},
commit: true,
onAuthorize: function (data, actions) {
return actions.payment.execute().then(function() {
document.querySelector('#paypal-button-container').innerText = 'Payment Complete!';
});
}
}, '#paypal-button');
</script>
But, if I supply input_fields like the code below, it stops working and throws a console error:
paypal.Button.render({
env: 'sandbox',
client: {
sandbox: 'xxxxxx',
production: 'yyyyyy'
},
payment: function () {
var env = this.props.env;
var client = this.props.client;
return paypal.rest.payment.create(env, client, {
transactions: [
{
amount: { total: '1.00', currency: 'USD' }
}
]
}, {
input_fields: {
no_shipping: 1
}
});
},
commit: true,
onAuthorize: function (data, actions) {
return actions.payment.execute().then(function() {
document.querySelector('#paypal-button-container').innerText = 'Payment Complete!';
});
}
}, '#paypal-button');
This is the error detail:
In this last case, I see the PayPal button, the window opens when I click on it, but after a few seconds the window closes itself and gives the console error provided here.
What am I missing?
UPDATE
As #bluepnume pointed out, if I switch from sandbox to production environment, the problem disappears.
But, if I also supply first_name and last_name in input_fields, I get another console error no matter if I'm in sandbox or production environment.
This is the code snippet:
, {
input_fields: {
no_shipping: 1,
first_name: 'Abc',
last_name: 'Dfg'
}
}
And this is the error message:
This is a known issue that's being tracked. For what it's worth, if you run in production mode, the issue should not be present.
EDIT: For the second issue, looks like this is not a valid request format. You should be able to see in your network tab:
Are you looking for the payer_info field for the payments api? https://developer.paypal.com/docs/api/payments/
Concerning the first issue, it seems everything is working well now. The "no_shipping" option can be used even in test conditions.

Categories