Skip to content
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

Adyen doesn't show #248

Open
rodrigoricky opened this issue Oct 30, 2021 · 18 comments
Open

Adyen doesn't show #248

rodrigoricky opened this issue Oct 30, 2021 · 18 comments

Comments

@rodrigoricky
Copy link

Adyen Payment option doesn't show in payment, I added Adyen in the settings and filled out the keys

image

@mrvautin
Copy link
Owner

Can you give more information? I just tested and Adyen is working for me. Does your terminal show any errors?

@rodrigoricky
Copy link
Author

Terminal doesn't show any errors, it's just Ayden doesn't appear on the payment options (ss above)

@mrvautin
Copy link
Owner

Could you check the browser console too for any errors. It's highly likely a config issue given it's working perfectly fine for me.

@rodrigoricky
Copy link
Author

image

@rodrigoricky
Copy link
Author

Quick question: How do I implement this on my version? I tried putting the code, doesn't work.

@mrvautin
Copy link
Owner

Quick question: How do I implement this on my version? I tried putting the code, doesn't work.

Added in 41c997e.

@mrvautin mrvautin reopened this Oct 30, 2021
@mrvautin
Copy link
Owner

Terminal doesn't show any errors, it's just Ayden doesn't appear on the payment options (ss above)

Could you show the config where you are turning on Adyen? Maybe even share your Adyen config with the sensitive parts removed?

@rodrigoricky
Copy link
Author

rodrigoricky commented Oct 30, 2021

Alr, and also to let you know I modified the code but I am not sure if it was the one causing the error, so I was trying to add GCash as an payment option for the site and here's the modified code (not really much modified)

// adyen.js btw
const express = require('express');
const { indexOrders } = require('../indexing');
const numeral = require('numeral');
const { Client, CheckoutAPI } = require('@adyen/api-library');
const { getId, sendEmail, getEmailTemplate } = require('../common');
const { getPaymentConfig } = require('../config');
const { emptyCart } = require('../cart');
const router = express.Router();

router.post('/setup', async (req, res, next) => {
    const adyenConfig = getPaymentConfig('adyen');

    const client = new Client({
        apiKey: adyenConfig.apiKey,
        environment: adyenConfig.environment
    });
    const checkout = new CheckoutAPI(client);
    let paymentsResponse;
    try{
        paymentsResponse = await checkout.paymentMethods({
            amount: {
                currency: 'PHP',
                value: 0
            },
            countryCode: 'PH',
            channel: 'Web',
            merchantAccount: adyenConfig.merchantAccount
  });
    }catch(ex){
        console.log('Exception getting supported payment methods', ex.message);
        res.status(400).json({ message: `Failed to retrieve payment methods.${ex.message}` });
    }
    res.status(200).json({
        paymentsResponse,
        environment: adyenConfig.environment,
        originKey: adyenConfig.originKey
    });
});

router.post('/checkout_action', async (req, res, next) => {
    const db = req.app.db;
    const config = req.app.config;
    const adyenConfig = getPaymentConfig('adyen');

    const client = new Client({
        apiKey: adyenConfig.apiKey,
        environment: adyenConfig.environment
    });

// Rest are the same code as in the repo

@rodrigoricky
Copy link
Author

Used wrong link - here's the correct link: https://docs.adyen.com/payment-methods/gcash/api-only

@mrvautin
Copy link
Owner

I've updated the Adyen integration to the latest and greatest here: 7c29782.

Note: The configuration changes: /config/payment/config/adyen.json

I can't test the specific payment method you are trying to use. Let me know how you get on.

@rodrigoricky
Copy link
Author

rodrigoricky commented Oct 31, 2021

So, I just filled out the new config of Adyen and I tried running it but returns this error while running it.

image

Edit: Nevermind, I accidentally added an old config line

@rodrigoricky
Copy link
Author

So I tried to setup the Adyen, and it still the same as earlier but now it has error on console:

image
image

Error only show when I am on checkout page

@mrvautin
Copy link
Owner

There was come config values which were removed. Check your config matches the adyen.json example. Checking carefully there is no old configs that are no longer needed with the new version.

@rodrigoricky
Copy link
Author

Here is my current config for adyen

{
    "description": "Card payment",
    "environment": "test",
    "apiKey": "API here",
    "clientKey": "key here",
    "merchantAccount": "Account here",
    "currency": "AUD",
    "countryCode": "AU"
}

@mrvautin
Copy link
Owner

mrvautin commented Oct 31, 2021

I think the payment type you want is quite niche and I'm not sure most will benefit by me adding it to master.

Re-reading the guide, is seems the GCash payment method isn't supported on the drop-in UI/integration which I've built for.

It looks easy enough to integrate though. You can simply add something like this code to your /setup endpoint in adyen.js: https://docs.adyen.com/payment-methods/gcash/api-only#api-only-payments

Then something like this (not tested at all) in /public/javascripts/common.js:

if($('#dropin-container').length > 0){
        $.ajax({
            method: 'POST',
            url: '/adyen/setup'
        })
        .done(async function(response){
             $('#adyen-gcash-link').attr('href', response.action.url);
        })
        .fail(function(msg){
            showNotification(msg.responseJSON.message, 'danger');
        });
    };

The idea is to get the response from /adyen/setup and set the URL of the link on the payment form.

Then in /views/partials/payments/adyen.hbs add something like:

<div>
    <a href="#" class="btn btn-primary" id="adyen-gcash-link"></a>
</div>

@rodrigoricky
Copy link
Author

Alright, but in the code that you sent me, should I replace it with the current code in the script or just add those? And for the GCash API, I think all are already except for the paymentMethod right?

// COMMON.JS
 if($('#dropin-container').length > 0){
        $.ajax({
            method: 'POST',
            url: '/adyen/setup'
        })
        .done(async function(response){
            const configuration = {
                environment: response.environment,
                clientKey: response.clientKey,
                session: {
                    id: response.paymentsResponse.id,
                    sessionData: response.paymentsResponse.sessionData
                },
                onPaymentCompleted: (result, component) => {
                    console.log('result', result);
                    console.log('component', component);
                    if($('#shipping-form').validator('validate').has('.has-error').length === 0){
                        $.ajax({
                            type: 'POST',
                            url: '/adyen/checkout_action',
                            data: {
                                paymentCode: result.resultCode,
                                paymentId: component._id
                            }
                        }).done((response) => {
                            window.location = '/payment/' + response.paymentId;
                        }).fail((response) => {
                            showNotification('Failed to complete transaction', 'danger', true);
                        });
                    }
                },
                onError: (error, component) => {
                    console.log(error.name, error.message, error.stack, component);
                },
                paymentMethodsConfiguration: {
                    hasHolderName: false,
                    holderNameRequired: false,
                    billingAddressRequired: false
                }
            };
            const checkout = await AdyenCheckout(configuration);
            checkout.create('dropin').mount('#dropin-container');
        })
        .fail(function(msg){
            showNotification(msg.responseJSON.message, 'danger');
        });
    };

@rodrigoricky
Copy link
Author

This is my current code on adyen.js

const payload = {
        merchantAccount: adyenConfig.merchantAccount,
        amount: {
            currency: adyenConfig.currency,
            value: numeral(req.session.totalCartAmount).format('0.00').replace('.', '')
        },
	paymentMethod: {
		type: 'gcash',
		storedPaymentMethodId: "7219687191761347"
			},
        returnUrl: `${config.baseUrl}/adyen/checkout_return`,
        reference: Object.keys(req.session.cart)[0],
        countryCode: adyenConfig.countryCode,
        shopperEmail: req.session.customerEmail
    };

I don't really know how it should be even though I read the docs
image

@mrvautin
Copy link
Owner

Ok. I've had a quick play and got it working.

adyen.js:

router.post('/setup', async (req, res, next) => {
    const config = req.app.config;
    const adyenConfig = getPaymentConfig('adyen');

    const payload = {
        merchantAccount: adyenConfig.merchantAccount,
        amount: { currency: 'PHP', value: 1000 },
        paymentMethod: {
            type: 'gcash'
        },
        returnUrl: `${config.baseUrl}/adyen/checkout_return`,
        reference: Object.keys(req.session.cart)[0]
    };

    let paymentsResponse;
    try{
        paymentsResponse = await got.post(`https://checkout-${adyenConfig.environment}.adyen.com/v67/payments'`, {
            headers: {
                'content-type': 'application/json',
                'x-API-key': adyenConfig.apiKey
            },
            json: payload
        });
        paymentsResponse = JSON.parse(paymentsResponse.body);
    }catch(ex){
        console.log('Exception getting supported payment methods', ex.message);
        res.status(400).json({ message: `Failed to retrieve payment methods.${ex.message}` });
        return;
    }
    res.status(200).json({
        paymentsResponse,
        environment: adyenConfig.environment
    });
});

common.js:

if($('#adyen-gcash-container').length > 0){
        $.ajax({
            method: 'POST',
            url: '/adyen/setup'
        })
        .done(async function(response){
            $('#adyen-gcash-link').attr('href', response.paymentsResponse.action.url);
            $('#adyen-gcash-link').text('Pay GCash');
        })
        .fail(function(msg){
            showNotification(msg.responseJSON.message, 'danger');
        });
};

adyen.hbs

<div>
    <div class="mb-2">{{@root.paymentConfig.adyen.description}}</div>
    <div id="adyen-gcash-container">
        <a href="#" class="btn btn-primary" id="adyen-gcash-link">Loading...</a>
    </div>
</div>

Note: I have no idea what GCash actually is and how to test a payment so the /checkout_action return code will need some work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants