- 
                Notifications
    
You must be signed in to change notification settings  - Fork 4
 
Pl 1537 #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Pl 1537 #23
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,38 +1,26 @@ | ||
| function shippingCb(address, tokenCallback) { | ||
| tokenCallback({ // Can return price based on address | ||
| shippingMethods: [ | ||
| { | ||
| id: '0', | ||
| name: 'Standard Ground (5-9 business days)', | ||
| deliveryTime: '5 - 9 Business Days', | ||
| cost: 0 | ||
| }, | ||
| ], | ||
| tax: 0 | ||
| }); | ||
| function initiatePayment() { | ||
| var XHR = new XMLHttpRequest(); | ||
| 
     | 
||
| // Set up our request | ||
| XHR.open('POST', 'http://localhost:3000/transfer', true); | ||
| 
     | 
||
| XHR.setRequestHeader("Content-Type", "application/json; charset=utf-8"); | ||
| 
     | 
||
| var data = $.param({ | ||
| merchantId: 'Merchant 123', | ||
| amount: 4.99, | ||
| currency: 'EUR', | ||
| description: 'Book Purchase', | ||
| destination: 'DE16700222000072880129' | ||
| }); | ||
| 
     | 
||
| // Define what happens on successful data submission | ||
| XHR.addEventListener("load", function(event) { | ||
| window.location.replace(event.target.responseURL); | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you are using the redirect flow here, but you can keep working with the popup, check merchant-demo code: https://github.com/tokenio/merchant-demo/blob/master/src/components/TokenEnablerButton/index.js#L74 it can take the token request url instead of terms, let me know if you need my help :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we want to demonstrate plain redirect since that's what our documentation shows. I originally tried using the bindButton set up but it caused all sorts of problems and confusion, so figured for the sample we're giving to devs we should keep it as plain as can be, and show that all Token specific stuff can be kept to the backend 😀  | 
||
| }); | ||
| 
     | 
||
| // Send the data; HTTP headers are set automatically | ||
| XHR.send(data); | ||
| } | ||
| 
     | 
||
| // Initializes the Quick Checkout Button | ||
| Token.styleButton({ // Sets up the Quick Checkout button | ||
| id: "tokenPayBtn", | ||
| label: "Token Quick Checkout" | ||
| }).bindPayButton( | ||
| { // Terms | ||
| alias: { // Merchant alias | ||
| type: 'EMAIL', | ||
| value: '{alias}' // (filled in by server) | ||
| }, | ||
| amount: 4.99, // Amount | ||
| currency: 'EUR', // Currency | ||
| destinations: [{account: {sepa: { iban: "DE16700222000072880129"}}}] | ||
| }, | ||
| shippingCb, // Shipping callback (null for "virtual" goods) | ||
| function(data) { // Success callback | ||
| $.post( | ||
| 'http://localhost:3000/transfer', | ||
| data); | ||
| }, | ||
| function(error) { // Failure callback | ||
| console.log('Something\'s wrong!', error); | ||
| } | ||
| ); | ||
| document.getElementById("tokenPayBtn").onclick = initiatePayment; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you are relying on jQuery for this, why not use $.post instead of native XMLHttpRequest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There were problems with the redirect part when I was using $.post, ended up with preflight response errors from the web app. This way didn't cause those errors, could be worth playing with to make it consistent though.