< All Topics
Print

Mypay.js Javascript Library

Mypay JavaScript implementation removes compliance responsibilities, allows you to fully customize the end-user experience, and unlocks the power of Mypay API without having worries about PCI Compliance. This would require minimal development effort from your side. With Mypay.js javascript library you can collect sensitive information from the user and create representative Tokens for safely sending that data to your servers. All sensitive information is handled by Mypay. js, which is fully PCI Compliant.

To get started, include this script on your html page:

<script src="https://api.mypay.gr/Content/js/v1/mypay.js"></script>

There are 2 different scenarios available to use.

1st Scenario: Checkout page will appear on your website using pop up:

In this scenario you have to add your Company, your Project, set up a payment method and create a checkout page on Mypay dashboard. Checkout pages are created automatically when you create a product, but you can create your own checkout page manually, as well. The second step will be to run the following script on your html page:

<script>
    Mypay.Checkout({
        publicCheckoutPageID: YOUR_CHECKOUT_PAGE_ID
    });
</script>

You can find your checkout page ID by visiting your check out page on Mypay dashboard.

Note that if you are planning to add paypal on you custom checkout form using javascript library you have to put the following tag on your html page:

<div id="YOUR_DIV_ID"></div>

After doing this step, you have to put the following script, as well:

<script>
    Mypay.Paypal({
        divID: 'YOUR_DIV_ID',
        publicCheckoutPageID: YOUR_CHECKOUT_PAGE_ID,
        productID: YOUR_PRODUCT_ID,
        productQuantity: YOUR_PRODUCT_QUANTITY,
        customerToken: 'YOUR_CUSTOMER_TOKEN',
        showOnlyPaymentUI: true
    });
</script>

The following parameters can be used in JavaScript function Mypay.Checkout:

Parameter nameParameter description
long projectIDWhen provided, checkout will use your first checkout page or create one if none found
long invoiceIDWhen provided, checkout will prefill products, customer
long publicCheckoutPageIDThe id of your checkout page
long productIDSpecify a product by id
int productQuantitySpecify the product’s quantity
string currencySpecify a 3-letter currency code to display checkout amounts (e.g USD)
decimal? amountWhen provided, a specific amount to charge the customer (a dummy product will be created)
string firstNameWhen provided, prefill customer info
string lastNameWhen provided, prefill customer info
string emailWhen provided, prefill customer info
string companyWhen provided, prefill customer info
string phoneWhen provided, prefill customer info
string billingAddress1When provided, prefill customer info
string billingAddress2When provided, prefill customer info
string billingCountryWhen provided, prefill customer info
string billingStateWhen provided, prefill customer info
string billingCityWhen provided, prefill customer info
string billingZipWhen provided, prefill customer info
bool shippingSameAsBillingWhen provided, prefill customer info
string shippingAddress1When provided, prefill customer info
string shippingAddress2When provided, prefill customer info
string shippingCountryWhen provided, prefill customer info
string shippingStateWhen provided, prefill customer info
string shippingCityWhen provided, prefill customer info
string shippingZipWhen provided, prefill customer info
bool issueInvoiceWhen provided, we create and send an invoice to customer
bool captureWhen provided, if false we just authorize the transaction, if true we both authorize-capture the transaction
long[] vendorIDWhen provided, we show products associated with these vendor IDs
bool hideHeaderFooterWhen provided, we show/hide the checkout header/footer
string merchantUniqueIDWhen provided, we set this unique id to the transaction metadata
string customerTokenWhen provided, a specific customer is used*
bool collectCustomerInfoWhen provided, customer details are required to be collected
bool hideCookieNoticeWhen provided we hide the accept cookies notice
string uniqueCustomerIDWhen provided, a specific customer is used
long businessIDWhen provided we assign a specific customer business to the transaction
decimal taxWhen provided, we override the default project/product tax rate
string checkoutTokenWhen provided, we use data for checkout created previously via api/Checkout/CreateToken
bool showOnlyPaymentUIWhen provided, we show only the main payment UI (credit card, paypal button etc.)
long paymentTypeIDWhen provided, we pre-select a payment type if it is available. List of available payment types:

1 Paypal
5 Sepa
12 ACH
long paymentMethodIDWhen provided, we pre-select a payment method

*You can find customer token by checking customer panel on Mypay dashboard or via API. 

2nd Scenario: Checkout page will appear directly on your website using custom button and passes a Mypay token  to a JavaScript callback:

Any merchant or service merchant provider who want to use this scenario has to be PCI – DSS compliant (SAQ A). To securely collect card details from your customers, you need to place the “data-mypay” tag to each of your fields containing customer and credit card details, as the example below:

<input type="email" data-mypay="email" placeholder="e-mail">
<input type="text" data-mypay="firstName" placeholder="first name">
<input type="text" data-mypay="lastName" placeholder="last name">
<input type="text" data-mypay="billingAddress" placeholder="billing address">
<input type="text" data-mypay="zip" placeholder="zip">
<input type="number" data-mypay="number" placeholder="number">
<input type="number" data-mypay="month" placeholder="month">
<input type="number" data-mypay="year" placeholder="year">
<input type="number" data-mypay="cvv" placeholder="cvv">

The following parameters can be used in order to create token:

NameRequiredTypeDescription
subdomainstringYour Mypay subdomain
amountdecimalMay be required when you are processing with 3D Secure (e.g: 25.55)
currencystringMay be required when you are processing with 3D Secure (e.g: USD)
emailXstringCustomer email
firstNameXstringCustomer first name
lastNameXstringCustomer last name
billingAddressXstringCustomer billing address
zipXstringCustomer billing zip
vatCountrystringCustomer vat country code (e.g: DE)
vatNumberstringCustomer vat number (e.g: 123456789)
numberXstringCredit card number
monthXintCredit card expiration month
yearXintCredit card expiration year
cvvXintCredit card CVV/CVC code
paymentMethodIDlong?When provided, we pre-select a payment method

The payment details collected using our library can then be converted into a token, using a handler function like this one:

<script>
    function createToken() {
        Mypay.SetPublicKey('YOUR_PUBLIC_KEY');

        Mypay.CreateToken().done(function (token) {
            console.log(token);
        }).fail(function (error) {
            console.log(error);
        });
    }
</script>

Go to Mypay dashboard -> Management console -> Security and copy the Public Key. 

Paste the Public Key on the javascript. Sends billing information to Mypay to store as a token, sending that the credit card token back to you. Once Mypay.js has stored your customer’s sensitive data and given you a credit card token, you will have 30 minutes to use it in our API. Expired tokens are permanently removed from the Mypay servers. In case you want to process multiple charges manually (for example using usage based billing scenarios), you have to use a permanent token which is created the same time with the temporary token. There are 2 different ways to obtain a permanent token:

1.       Go to https://api.mypay.gr/docs/index#!/Charge/Charge_Post and send request using the temporary token.

2.       Go to https://api.mypay.gr/docs/index#!/Customers/Customers_Get and add the customer ID into search field.  

An API callback is always required. Visit https://api.mypay.gr/docs/index#!/Charge/Charge_Post in order to complete this step.

Alternatively, you can use Direct credit card tokenization using JS:

You can use any of the parameters as above

In this case go to Mypay dashboard -> Management console -> Security and copy the Public Key. Paste the Public Key on the following javascript:

<script>
    function createTokenDirect() {
        Mypay.SetPublicKey('YOUR_PUBLIC_KEY');

        var data = {
            email: 'john@example.com',
            firstName: 'John',
            lastName: 'Doe',
            billingAddress: '1st Street 77',
            zip: '12345',
            number: '4242424242424242',
            month: '10',
            year: '2020',
            cvv: '735'
        };

        Mypay.CreateToken(data).done(function (token) {
            console.log(token);
        }).fail(function (error) {
            console.log(error);
        });
    }
</script>

Checkout page examples:

– Product selection

<script>
    Mypay.Checkout({
        'PublicCheckoutPage.ID': 1
    });
</script>

– Customer info (with selected product)

<script>
    Mypay.Checkout({
        'PublicCheckoutPage.ID': YOUR_CHECKOUT_PAGE_ID,
        'CartProducts[0].ID': YOUR_PRODUCT_ID,
        'CartProducts[0].Quantity': YOUR_PRODUCT_QUANTITY
    });
</script>

– Payment method selection (with selected product and customer)

<script>
    Mypay.Checkout({
        'PublicCheckoutPage.ID': YOUR_CHECKOUT_PAGE_ID,
        'CartProducts[0].ID': YOUR_PRODUCT_ID,
        'CartProducts[0].Quantity': YOUR_PRODUCT_QUANTITY,
        'Customer.Token': YOUR_CUSTOMER_TOKEN
    });
</script>

– Payment method selection (with selected new products, customer and vendor with custom amount/percent)

<script>
    Mypay.Checkout({
        'PublicCheckoutPage.ID': YOUR_CHECKOUT_PAGE_ID,
        'CartProducts[0].ProductType': YOUR_PRODUCT_TYPE,
        'CartProducts[0].Title': YOUR_PRODUCT_TITLE,
        'CartProducts[0].Description': YOUR_PRODUCT_DESCRIPTION,
        'CartProducts[0].Price': YOUR_PRODUCT_PRICE,
        'CartProducts[0].Quantity': YOUR_PRODUCT_QUANTITY,
        'CartProducts[0].Vendors[0].ID': YOUR_VENDOR_ID,
        'CartProducts[0].Vendors[0].CommisionAmountOverride': YOUR_VENDORS_AMOUNT,
        'CartProducts[1].ProductType': YOUR_PRODUCT_TYPE,
        'CartProducts[1].Title': YOUR_PRODUCT_TITLE,
        'CartProducts[1].Description': YOUR_PRODUCT_DESCRIPTION,
        'CartProducts[1].Price': YOUR_PRODUCT_PRICE,
        'CartProducts[1].Quantity': YOUR_PRODUCT_QUANTITY,
        'CartProducts[1].Vendors[0].ID': YOUR_VENDOR_ID,
        'CartProducts[1].Vendors[0].CommisionPercentOverride': YOUR_VENDORS_PERCENT,
        'Customer.Token': YOUR_CUSTOMER_TOKEN
    });
</script>

Table of Contents
< All Topics
Print

Mypay.js Javascript Library

Mypay JavaScript implementation removes compliance responsibilities, allows you to fully customize the end-user experience, and unlocks the power of Mypay API without having worries about PCI Compliance. This would require minimal development effort from your side. With Mypay.js javascript library you can collect sensitive information from the user and create representative Tokens for safely sending that data to your servers. All sensitive information is handled by Mypay. js, which is fully PCI Compliant.

To get started, include this script on your html page:

<script src="https://api.mypay.gr/Content/js/v1/mypay.js"></script>

There are 2 different scenarios available to use.

1st Scenario: Checkout page will appear on your website using pop up:

In this scenario you have to add your Company, your Project, set up a payment method and create a checkout page on Mypay dashboard. Checkout pages are created automatically when you create a product, but you can create your own checkout page manually, as well. The second step will be to run the following script on your html page:

<script>
    Mypay.Checkout({
        publicCheckoutPageID: YOUR_CHECKOUT_PAGE_ID
    });
</script>

You can find your checkout page ID by visiting your check out page on Mypay dashboard.

Note that if you are planning to add paypal on you custom checkout form using javascript library you have to put the following tag on your html page:

<div id="YOUR_DIV_ID"></div>

After doing this step, you have to put the following script, as well:

<script>
    Mypay.Paypal({
        divID: 'YOUR_DIV_ID',
        publicCheckoutPageID: YOUR_CHECKOUT_PAGE_ID,
        productID: YOUR_PRODUCT_ID,
        productQuantity: YOUR_PRODUCT_QUANTITY,
        customerToken: 'YOUR_CUSTOMER_TOKEN',
        showOnlyPaymentUI: true
    });
</script>

The following parameters can be used in JavaScript function Mypay.Checkout:

Parameter nameParameter description
long projectIDWhen provided, checkout will use your first checkout page or create one if none found
long invoiceIDWhen provided, checkout will prefill products, customer
long publicCheckoutPageIDThe id of your checkout page
long productIDSpecify a product by id
int productQuantitySpecify the product’s quantity
string currencySpecify a 3-letter currency code to display checkout amounts (e.g USD)
decimal? amountWhen provided, a specific amount to charge the customer (a dummy product will be created)
string firstNameWhen provided, prefill customer info
string lastNameWhen provided, prefill customer info
string emailWhen provided, prefill customer info
string companyWhen provided, prefill customer info
string phoneWhen provided, prefill customer info
string billingAddress1When provided, prefill customer info
string billingAddress2When provided, prefill customer info
string billingCountryWhen provided, prefill customer info
string billingStateWhen provided, prefill customer info
string billingCityWhen provided, prefill customer info
string billingZipWhen provided, prefill customer info
bool shippingSameAsBillingWhen provided, prefill customer info
string shippingAddress1When provided, prefill customer info
string shippingAddress2When provided, prefill customer info
string shippingCountryWhen provided, prefill customer info
string shippingStateWhen provided, prefill customer info
string shippingCityWhen provided, prefill customer info
string shippingZipWhen provided, prefill customer info
bool issueInvoiceWhen provided, we create and send an invoice to customer
bool captureWhen provided, if false we just authorize the transaction, if true we both authorize-capture the transaction
long[] vendorIDWhen provided, we show products associated with these vendor IDs
bool hideHeaderFooterWhen provided, we show/hide the checkout header/footer
string merchantUniqueIDWhen provided, we set this unique id to the transaction metadata
string customerTokenWhen provided, a specific customer is used*
bool collectCustomerInfoWhen provided, customer details are required to be collected
bool hideCookieNoticeWhen provided we hide the accept cookies notice
string uniqueCustomerIDWhen provided, a specific customer is used
long businessIDWhen provided we assign a specific customer business to the transaction
decimal taxWhen provided, we override the default project/product tax rate
string checkoutTokenWhen provided, we use data for checkout created previously via api/Checkout/CreateToken
bool showOnlyPaymentUIWhen provided, we show only the main payment UI (credit card, paypal button etc.)
long paymentTypeIDWhen provided, we pre-select a payment type if it is available. List of available payment types:

1 Paypal
5 Sepa
12 ACH
long paymentMethodIDWhen provided, we pre-select a payment method

*You can find customer token by checking customer panel on Mypay dashboard or via API. 

2nd Scenario: Checkout page will appear directly on your website using custom button and passes a Mypay token  to a JavaScript callback:

Any merchant or service merchant provider who want to use this scenario has to be PCI – DSS compliant (SAQ A). To securely collect card details from your customers, you need to place the “data-mypay” tag to each of your fields containing customer and credit card details, as the example below:

<input type="email" data-mypay="email" placeholder="e-mail">
<input type="text" data-mypay="firstName" placeholder="first name">
<input type="text" data-mypay="lastName" placeholder="last name">
<input type="text" data-mypay="billingAddress" placeholder="billing address">
<input type="text" data-mypay="zip" placeholder="zip">
<input type="number" data-mypay="number" placeholder="number">
<input type="number" data-mypay="month" placeholder="month">
<input type="number" data-mypay="year" placeholder="year">
<input type="number" data-mypay="cvv" placeholder="cvv">

The following parameters can be used in order to create token:

NameRequiredTypeDescription
subdomainstringYour Mypay subdomain
amountdecimalMay be required when you are processing with 3D Secure (e.g: 25.55)
currencystringMay be required when you are processing with 3D Secure (e.g: USD)
emailXstringCustomer email
firstNameXstringCustomer first name
lastNameXstringCustomer last name
billingAddressXstringCustomer billing address
zipXstringCustomer billing zip
vatCountrystringCustomer vat country code (e.g: DE)
vatNumberstringCustomer vat number (e.g: 123456789)
numberXstringCredit card number
monthXintCredit card expiration month
yearXintCredit card expiration year
cvvXintCredit card CVV/CVC code
paymentMethodIDlong?When provided, we pre-select a payment method

The payment details collected using our library can then be converted into a token, using a handler function like this one:

<script>
    function createToken() {
        Mypay.SetPublicKey('YOUR_PUBLIC_KEY');

        Mypay.CreateToken().done(function (token) {
            console.log(token);
        }).fail(function (error) {
            console.log(error);
        });
    }
</script>

Go to Mypay dashboard -> Management console -> Security and copy the Public Key. 

Paste the Public Key on the javascript. Sends billing information to Mypay to store as a token, sending that the credit card token back to you. Once Mypay.js has stored your customer’s sensitive data and given you a credit card token, you will have 30 minutes to use it in our API. Expired tokens are permanently removed from the Mypay servers. In case you want to process multiple charges manually (for example using usage based billing scenarios), you have to use a permanent token which is created the same time with the temporary token. There are 2 different ways to obtain a permanent token:

1.       Go to https://api.mypay.gr/docs/index#!/Charge/Charge_Post and send request using the temporary token.

2.       Go to https://api.mypay.gr/docs/index#!/Customers/Customers_Get and add the customer ID into search field.  

An API callback is always required. Visit https://api.mypay.gr/docs/index#!/Charge/Charge_Post in order to complete this step.

Alternatively, you can use Direct credit card tokenization using JS:

You can use any of the parameters as above

In this case go to Mypay dashboard -> Management console -> Security and copy the Public Key. Paste the Public Key on the following javascript:

<script>
    function createTokenDirect() {
        Mypay.SetPublicKey('YOUR_PUBLIC_KEY');

        var data = {
            email: 'john@example.com',
            firstName: 'John',
            lastName: 'Doe',
            billingAddress: '1st Street 77',
            zip: '12345',
            number: '4242424242424242',
            month: '10',
            year: '2020',
            cvv: '735'
        };

        Mypay.CreateToken(data).done(function (token) {
            console.log(token);
        }).fail(function (error) {
            console.log(error);
        });
    }
</script>

Checkout page examples:

– Product selection

<script>
    Mypay.Checkout({
        'PublicCheckoutPage.ID': 1
    });
</script>

– Customer info (with selected product)

<script>
    Mypay.Checkout({
        'PublicCheckoutPage.ID': YOUR_CHECKOUT_PAGE_ID,
        'CartProducts[0].ID': YOUR_PRODUCT_ID,
        'CartProducts[0].Quantity': YOUR_PRODUCT_QUANTITY
    });
</script>

– Payment method selection (with selected product and customer)

<script>
    Mypay.Checkout({
        'PublicCheckoutPage.ID': YOUR_CHECKOUT_PAGE_ID,
        'CartProducts[0].ID': YOUR_PRODUCT_ID,
        'CartProducts[0].Quantity': YOUR_PRODUCT_QUANTITY,
        'Customer.Token': YOUR_CUSTOMER_TOKEN
    });
</script>

– Payment method selection (with selected new products, customer and vendor with custom amount/percent)

<script>
    Mypay.Checkout({
        'PublicCheckoutPage.ID': YOUR_CHECKOUT_PAGE_ID,
        'CartProducts[0].ProductType': YOUR_PRODUCT_TYPE,
        'CartProducts[0].Title': YOUR_PRODUCT_TITLE,
        'CartProducts[0].Description': YOUR_PRODUCT_DESCRIPTION,
        'CartProducts[0].Price': YOUR_PRODUCT_PRICE,
        'CartProducts[0].Quantity': YOUR_PRODUCT_QUANTITY,
        'CartProducts[0].Vendors[0].ID': YOUR_VENDOR_ID,
        'CartProducts[0].Vendors[0].CommisionAmountOverride': YOUR_VENDORS_AMOUNT,
        'CartProducts[1].ProductType': YOUR_PRODUCT_TYPE,
        'CartProducts[1].Title': YOUR_PRODUCT_TITLE,
        'CartProducts[1].Description': YOUR_PRODUCT_DESCRIPTION,
        'CartProducts[1].Price': YOUR_PRODUCT_PRICE,
        'CartProducts[1].Quantity': YOUR_PRODUCT_QUANTITY,
        'CartProducts[1].Vendors[0].ID': YOUR_VENDOR_ID,
        'CartProducts[1].Vendors[0].CommisionPercentOverride': YOUR_VENDORS_PERCENT,
        'Customer.Token': YOUR_CUSTOMER_TOKEN
    });
</script>

Table of Contents
@media only screen and (min-width:768px){#eckb-article-page-container-v2 #eckb-article-body #eckb-article-content #eckb-article-content-header-v2 #eckb-article-content-header-row-1,#eckb-article-page-container-v2 #eckb-article-body #eckb-article-content #eckb-article-content-header-v2 #eckb-article-content-header-row-2,#eckb-article-page-container-v2 #eckb-article-body #eckb-article-content #eckb-article-content-header-v2 #eckb-article-content-header-row-3,#eckb-article-page-container-v2 #eckb-article-body #eckb-article-content #eckb-article-content-header-v2 #eckb-article-content-header-row-4,#eckb-article-page-container-v2 #eckb-article-body #eckb-article-content #eckb-article-content-header-v2 #eckb-article-content-header-row-5{flex-direction:row;}}#eckb-article-content-header-row-1{margin-bottom:8px;}#eckb-article-content-header-row-1 .eckb-article-content-header-row-left-group,#eckb-article-content-header-row-1 .eckb-article-content-header-row-right-group{align-items:center;}.eckb-article-content-toolbar-button-container{background-color:#ffffff;padding:10px 10px 10px 10px;margin:0px 0px 0px 0px;border-radius:0px;border-width:0px;border-color:#ffffff;border-style:solid;}.eckb-article-content-toolbar-button-container .eckb-toolbar-button-text{color:#000000;font-size:15px;}.eckb-article-content-toolbar-button-container .eckb-toolbar-button-icon{color:#000000;font-size:20px;}.eckb-article-content-toolbar-button-container:hover{background-color:#ffffff;}.eckb-article-content-toolbar-button-container:hover .eckb-toolbar-button-text{color:#000000;}.eckb-article-content-toolbar-button-container:hover .eckb-toolbar-button-icon{color:#000000;}#eckb-article-content-header-row-2{margin-bottom:0px;}#eckb-article-content-header-row-2 .eckb-article-content-header-row-left-group,#eckb-article-content-header-row-2 .eckb-article-content-header-row-right-group{align-items:flex-end;}#eckb-article-content-footer .epkb-article-navigation-container a{background-color:#f7f7f7;color:#1e73be;}#eckb-article-content-footer .epkb-article-navigation-container a:hover{background-color:#dee3e5;color:#6d6d6d;}#eckb-article-body .eckb-article-toc ul a.active{background-color:#1e73be;color:#ffffff;}#eckb-article-body .eckb-article-toc ul a:hover{background-color:#e1ecf7;color:#000000;}#eckb-article-body .eckb-article-toc__inner{border-color:#2b98e5;font-size:14px !important;background-color:#fcfcfc;}#eckb-article-body .eckb-article-toc__inner a{color:#2b98e5;font-size:14px !important;}#eckb-article-body .eckb-article-toc__title{color:#2b98e5;font-size:15px !important;}