How to embed Stripe Pricing tables in Angular app - stripe-payments

Reading Stripe docs regarding the embeddable Pricing tables feature - I have constructed a pricing table following the steps as described.
This results in a code snippet that can be used to embed the hosted pricing table on one's own website/application.
Example snippet;
<script async src="https://js.stripe.com/v3/pricing-table.js"></script>
<stripe-pricing-table pricing-table-id="xxx_xxxxxxxxxx"
publishable-key="pk_test_xxxxxxxxxx">
</stripe-pricing-table>
The examples in the docs relating to how to embed this snippet give only HTML and React examples.
I'd like to know how to achieve the same result in angular.
I have attempted to use Stipe Elements to build an element to hold the pricing table, but Elements does not seem to have a component for the new Pricing tables.

Yes at the moment Stripe Docs has no information for Angular.
Here is my solution suggestion with dynamic attribute placement from component to html view.
1. index.html
<head>
<!-- Paste the script snippet in the head of your app's index.html -->
<script async src="https://js.stripe.com/v3/pricing-table.js"></script>
</head>
2) in xyz.module.ts
import {NgModule, CUSTOM_ELEMENTS_SCHEMA} from '#angular/core';
#NgModule({
declarations: [
XyzComponent,
...
],
imports: [...],
schemas: [
CUSTOM_ELEMENTS_SCHEMA
]
})
3. in xyz.component.ts
public stripe_key: string = 'pk_test_***';
public stripe_table: string = 'prctbl_***'
4. in xyz.componet.html
<stripe-pricing-table
[attr.pricing-table-id]="stripe_table"
[attr.publishable-key]="stripe_key">
</stripe-pricing-table>
If you don't need dynamic publishable-key and pricing-table-id skip point 3 and hardcode point 4, as here:
xyz.componet.html
<stripe-pricing-table
pricing-table-id="prctbl_***"
publishable-key="pk_test_***">
</stripe-pricing-table>

I just found the solution and processed as followed :
Integrate the stripe script file inside your index.html.
Create and extends a component with HTMLElement and do as they say here
Then you had CUSTOM_ELEMENTS_SCHEMA from Angular core to your module :
#NgModule({
...
schemas: [CUSTOM_ELEMENTS_SCHEMA
})
Finally, call your component which embed the stripe pricing table web component and your pricing table will shows up properly in an Iframe.

Related

AngularJS 2 with .NetFramework 4.6

I'm currently making a web application with Asp.net MVC 5 (.Net Framework 4.6) and AngularJS 2.0 .
I take care the back-end and my friend takes care the front-end.
Now, he sends me 3 js files, 1 html file.
Can anyone help me to import those file to MVC 5 please ?
Thank you,
I´m assuming you are new to MVC...
Create a new MVC project.
Copy your js files to Scripts. (Drag from explorer to visual studio)
The best way to go with js is to make a bundle:
In app_start, open BundleConfig.cs
Create a new Bundle like this:
bundles.Add(new ScriptBundle("~/bundles/mybundle").Include(
"~/Scripts/myjs1.js",
"~/Scripts/myjs2.js",
"~/Scripts/myjs3.js"));
Now to render this bundle, open Views->Shared->_Layout.cshtml
Go to the bottom, find #Scripts.Render("~/bundles/jquery")
Add your bundle: #Scripts.Render("~/bundles/mybundle") Now, your js is available to all pages.
We need to create a controller. Right click Controllers folder -> add -> Controller
Select MVC5 Controller Empty.
Give it the name you like for this page.
You will see this:
public class testeController : Controller
{
// GET: teste
public ActionResult Index()
{
return View();
}
}
11. Right Click the Index in the code -> click in add View
12. VS will open the view. Paste your HTML here.
You are good to go!
Things to keep in mind 1 - ROUTES:
MVC default route (URL) is /controller/Action/id
In the example above, your url will be: /teste or /teste/index because it´s the controllers name.
If not provided MVC uses Home as controller name and Index as action name and id is optional.
So, if your page is the home page for the site put it in the Views -> Home -> index.cshtml
Things to keep in mind 2 - BUNDLES:
Bundles are available for all pages, if you need your js in only one page, to this:
Open your View, go to the bottom of the file and do this:
#section scripts{
<script src="~/Scripts/js1.js"></script>
<script src="~/Scripts/js2.js"></script>
<script src="~/Scripts/js3.js"></script>
}
Things to keep in mind 2 - LAYOUT:
MVC works divides your content into 2 files, stuff common to all pages, like navigation bar, footer, css and js calls reside in:
Views -> Shared -> _Layout.cs
Views are the changeable content in the middle of the page, look for the method #RenderBody() in _Layout.cshtml to find where your view will be rendered.
Maybe you will have to divide your friend´s html to have some in _layout and some in the View. This is quite common.
Good luck and Happy Coding!!
Sure,
Create an ../app folder and drop the js files
The html file you have, I suggest you copy paste its content into a razor view, ../Views/App/MyPage.cshtml
Then create a c# controller that will return that view AppController
public class AppController : Controller
{
public ActionResult MyPage()
{
return PartialView();
}
Like this https://github.com/victorantos/AngJobs/blob/master/AngJobs/Controllers/AppController.cs
Another important note, make sure your router is configured properly, like this
https://github.com/victorantos/AngJobs/blob/master/AngJobs/App_Start/RouteConfig.cs

Apostrophe CMS slideshow singleton not accessible

I'm attempting to add an image to a page type using a singleton set to the slideshow widgetType
The interface is working fine (can upload image, limits uploads to the set variable), but I cannot access the object in the templates
I am logging the page object with the below script in the page template, every other custom field works fine, just not the slideshow widget.
var data = {{ page | json }};
console.log(data);
Here is what is set in app.js
project: {
extend: 'apostrophe-fancy-page',
name: 'project',
label: 'Project',
addFields: [
{
name: 'thumb',
label: 'Thumbnail',
type: 'singleton',
widgetType: 'slideshow',
options: {
limit: 1
}
}
]
}
Any advice?
Hmm. You don't specify, but my suspicion is that you're trying to access the thumbnail from the template for a different page that has access to it as related-page information, e.g. page.ancestors or page.children. If the singleton were being rendered on the template for the page itself, you would have no trouble with this.
The thing about related-page information is that for performance reasons, Apostrophe limits how much information it includes in those arrays.
However, you can specify that you want more information. Here is an example from the pages property of the app.js file of one of our projects:
pages: {
// other config like page types goes here, then...
ancestorOptions: {
children: true,
areas: [ 'thumbnail' ]
},
descendantOptions: {
depth: 2,
areas: [ 'thumbnail' ]
}
}
Here we are enabling:
Include a .children array for each ancestor in page.ancestors, for accordion nav
Include the area called thumbnail for each ancestor
Include the area called thumbnail for each child of the current page (page.children)
Also include grandchildren page.children[0].children for dropdown nav
When you load more data, the price you pay is a little more time. This is a good compromise setup when you need a lot but you don't want to fetch thousands of pages and "hydrate" all of their widgets by fetching even more data.
If I'm mistaken and you are doing this on the page template for the page itself and it still doesn't work, please provide some examples and I can review those.
(I am one of the lead developers on Apostrophe. Apologies for not seeing this question sooner. StackOverflow is a good place for it and we'll be monitoring more closely in the future now that 2.0 stable has been released.)

Sails js render partial view

I'm new in SailsJS so i have a question about rendering partial views.
I've came from .NET world and partial views in ASP.NET MVC are much more clever than in sails. In .NET MVC i can provide some controller as partial view path and this controller will be executed and partial view will be rendered with that controller data.
For example I want to show some account info in the corner of my website. So in .NET i can call partial view, providing controller path, this controller will query account info, provide it to partial view, and then this result will be inserted to main view.
In Sails i can call partial view, but all data (locals) for partial view will be pushed there from main view. So i have to put account information in every controller in application?
How can i solve this problem?
In other questions i've found that I can take username from req.session but it does not solve all cases. How can i show three random topics in page footer for example?
I think you are looking at the wrong place about the partial views.
This is a front-end problem .What I use for such partial views is Angular UI-router . Actually I am not sure if using angular is in the scope of the solution for you,So I'll keep this short . If you feel my method is useful ,you can comment it ,and I'll elaborate further on how to do it .
Depends on the template engine, that you use.
With ejs you can use <%- include('someview') %> or <%- include('someview', { mydata: { foo: bar} }) %>
The latter allows the include file to be called several times with diff data. E.g. <%- include('someview', { mydata: foo }) %> will copy foo (from locals) to the mydata key. This will be added to locals, so all other locals are available too.
As for providing the actual data, you can use a sails service. Just add data to res.locals.myKeyForTheInclude.
You will have to call the service each time.
But you can add it in config/http as a middleware.
middleware: {
myFoo: myService.myFunc,
order: [
...
'myFoo', // before router
'router',
...
],
All that is left is that each template needs the include.
You can not avoid that, only the template knows where the include should be.
But if you use a layout, that maybe it fits into the layout.

Exception trying to load tab from ajax request using Ext.NET

I'm using asp.net mvc with ext.net and I'm trying to create a set of tabs that load information only when they are selected by the user.
I can manage to load a partial view into a tab/panel using the ContentFromAction functions:
But I can't figure out how to populate a tab/panel only when a tab is selected.
I've based my project on the Ext.NET MVC Examples Explorer version 2.5 code base and this code on the TabPanel > Basic > Ajax Load example found here
I've cut down the example as far as I can to reproduce the problem:
In my view I create the tab and configure the loader (exactly the same as the example project):
Index.cshtml
X.Panel()
.ID("Tab3")
.Title("Ajax Tab")
.BodyPadding(6)
.AutoScroll(true)
.Loader(X.ComponentLoader()
.Url(Url.Action("Ajax"))
.LoadMask(m => m.ShowMask = true)
.Params(new Parameter("containerId", "Tab3"))
.Mode(LoadMode.Html)
)
It correctly calls into my controller (exactly the same as the example project):
Axax_LoadController.cs
using System.Web.Mvc;
namespace Ext.Net.MVC.Examples.Areas.TabPanel_Basic.Controllers
{
public class Ajax_LoadController : Controller
{
public ActionResult Ajax(string containerId)
{
return View("Ajax");
}
}
}
Which in turn displays the appropriate view in the tab after it's been clicked on:
Ajax.cshtml (this works)
#using Ext.Net.MVC
<div>
<p>I am content loaded via Ajax when the tab is selected</p>
</div>
The problem begins if I try to add controls in my view, as follows:
Ajax.cshtml
#using Ext.Net.MVC
#{ var X = Html.X(); }
<div>
<p>I am content loaded via Ajax when the tab is selected</p>
#X.TextField().Text("I am a text field")
</div>
This fails with the exception:
ItemTag validation (_tkn_1): Reference token (init_script) was not found.
If I modify the file Ext call to return Html as follows:
Ajax.cshtml
#using Ext.Net.MVC
#{ var X = Html.X(); }
<div>
<p>I am content loaded via Ajax when the tab is selected</p>
#X.TextField().Text("I am a text field").ToHtmlString()
</div>
It correctly renders the following text in my selected tab:
I am content loaded via Ajax when the tab is selected
<#:item ref="init_script" index="0">Ext.create("Ext.form.field.Text",{renderTo:"App.id534c5fe0f159f3fb_Container",value:"I am a text field"});</#:item><div id="App.id534c5fe0f159f3fb_Container"></div>
I believe that the ext.net code is written by #geoffrey.mcgill on stack overflow so I'm hoping he can help rescue me.
You need to use a PartialViewResult. Please look at these examples.
Partial Content
Partial Items
Personally, I would recommend to follow the Partial Items example. You always can wrap any non-Ext.NET content in an Ext.NET Container. The benefit of this approach is the fact that you don't need to worry about destroying Ext.NET components if you reload the content. Though, anyway, I would recommend to set up explicit IDs for Ext.NET components in a partial view. At least, for top level components.

How I do create a animated loading indicator spotify apps

How I do use the loading_indicator.png provided in the design resources folder to make it act like an ajax loader?
This is how I display a loading indicator when starting my app, taken from the 'home' application (What's New). In your index.html:
<div class="loading">
<div class="throbber"><div></div></div>
</div>
In you app.css:
#import url("sp://import/css/eve.css");
adam.css being the dark Spotify theme and eve.css the light. Then, when your application is finished loading, just remove the element. You can do it with the dom methods in the spotify dom.js. In your app.js:
var dom = sp.require('sp://import/scripts/dom');
var loadingEl = dom.queryOne('.loading');
dom.destroy(loadingEl);
I don't know if the dom.js will be in the official API or not. Otherwise you can remove it any other way (standard dom methods, other js libraries you're using, etc):
var loadingEl = document.querySelector('.loading');
loadingEl.parentNode.removeChild(loadingEl);
Note that the above example does not necessarily use the loading_indicator.png but whatever images that are used by the adam.css and eve.css themes.
If you wan't to use the loader as a normal ajax loading indicator inside your app, then all the normal rules of web apps apply. Display loader when initiating ajax call, hide it in completed-callback, position it with css.
I realize this is an old topic, but with the 1.X API there is an easier way to do this by using the Throbber class which allows you to instantiate and hide fairly simply via JS.
var tracks = document.getElementById('tracks');
var throbber = Throbber.forElement(tracks);
// (wait for tracks to load and render)
throbber.hide();
Just make sure to include the Throbber class at the beginning of your JS:
require([
'$views/throbber#Throbber'
], function (Throbber) {

Resources