-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #314 from lyra/KJS-2280.1
chore(examples): update examples to use renderElements method
- Loading branch information
Showing
31 changed files
with
168 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...ples/ember/app/components/attach-form.hbs → .../ember/app/components/render-elements.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)'; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.