Skip to content

Commit

Permalink
Merge pull request #314 from lyra/KJS-2280.1
Browse files Browse the repository at this point in the history
chore(examples): update examples to use renderElements method
  • Loading branch information
s-yagues authored Nov 13, 2023
2 parents b9ab56b + 25bb728 commit 7cc7209
Show file tree
Hide file tree
Showing 31 changed files with 168 additions and 289 deletions.
9 changes: 3 additions & 6 deletions examples/angular/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { firstValueFrom } from 'rxjs'
styleUrls: ['./app.component.css']
})
export class AppComponent implements AfterViewInit {
title: string = 'Angular + KR.attachForm'
title: string = 'Angular example'
message: string = ''

constructor(private http: HttpClient, private chRef: ChangeDetectorRef) {}
Expand Down Expand Up @@ -41,11 +41,8 @@ export class AppComponent implements AfterViewInit {
)
.then(({ KR }) => KR.onSubmit(this.onSubmit))
.then(({ KR }) =>
KR.attachForm('#myPaymentForm')
) /* Attach a payment form to myPaymentForm div*/
.then(({ KR, result }) =>
KR.showForm(result.formId)
) /* show the payment form */
KR.renderElements('#myPaymentForm')
) /* Render the payment form into the specified selector*/
.catch(error => {
this.message = error.message + ' (see console for more details)'
})
Expand Down
2 changes: 1 addition & 1 deletion examples/angular/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<title>MinimalExample</title>
<title>Angular example</title>
<base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
Expand Down
57 changes: 0 additions & 57 deletions examples/ember/app/components/attach-form.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class='container'>
<h1>Ember + KR.attachForm</h1>
<h1>Ember Example</h1>
<div id='myPaymentForm'>
<div class='kr-smart-form'></div>
</div>
Expand Down
53 changes: 53 additions & 0 deletions examples/ember/app/components/render-elements.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import KRGlue from '@lyracom/embedded-form-glue';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';

export default class RenderElementsComponent extends Component {
@tracked message = '';
constructor(...args) {
super(...args);
const endpoint = '~~CHANGE_ME_ENDPOINT~~';
const publicKey = '~~CHANGE_ME_PUBLIC_KEY~~';
let formToken = 'DEMO-TOKEN-TO-BE-REPLACED';
// Generate the form token
fetch('http://localhost:3000/createPayment', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
paymentConf: { amount: 10000, currency: 'USD' },
}),
})
.then((res) => res.text())
.then((resp) => {
formToken = resp;
return KRGlue.loadLibrary(endpoint, publicKey);
})
.then(({ KR }) =>
KR.setFormConfig({
/* set the minimal configuration */
formToken: formToken,
'kr-language': 'en-US' /* to update initialization parameter */,
})
)
.then(({ KR }) =>
KR.onSubmit((paymentData) => {
fetch('http://localhost:3000/validatePayment', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(paymentData),
}).then((response) => {
if (response.status === 200) this.message = 'Payment successful!';
});
return false; // Return false to prevent the redirection
})
) // Custom payment callback
.then(({ KR }) =>
KR.renderElements('#myPaymentForm')
) /* create a payment form */
.catch((error) => {
this.message = error + ' (see console for more details)';
});
}
}
2 changes: 1 addition & 1 deletion examples/ember/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Emberjs</title>
<title>Emberjs Example</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
Expand Down
8 changes: 4 additions & 4 deletions examples/ember/app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{page-title "Emberjs"}}
{{page-title 'Emberjs'}}

{{!-- The following component displays Ember's default welcome message. --}}
<AttachForm />
{{!-- Feel free to remove this! --}}
{{! The following component displays Ember's default welcome message. }}
<RenderElements />
{{! Feel free to remove this! }}

{{outlet}}
30 changes: 7 additions & 23 deletions examples/ember/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/ember/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@
"edition": "octane"
},
"dependencies": {
"@lyracom/embedded-form-glue": "1.3.1"
"@lyracom/embedded-form-glue": "1.3.7"
}
}
Loading

0 comments on commit 7cc7209

Please sign in to comment.