Forum

Thread tagged as: Error, Shop

Payment Gateway set up

Hi I'm experimenting with the Braintree gateway in sandbox but I keep getting "There was an error processing your request. Try again". Here is my diagnostic -

Perch Runway: 2.8.31, PHP: 7.0.10, MySQL: mysqlnd 5.0.12-dev - 20150407 - $Id: 241ae00989d1995ffcbbf63d579943635faf9972 $, with PDO
Server OS: Darwin, apache2handler
Installed apps: content (2.8.31), assets (2.8.31), categories (2.8.31), perch_forms (1.8.3), perch_shop_orders (1.0.8), perch_shop_products (1.0.8), perch_shop (1.0.8), perch_members (1.5)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_members', 'perch_shop', 'perch_forms' );
PERCH_LOGINPATH: /perch
PERCH_PATH: /xxxx/yyyy/Sites/licoriceDesign/perch
PERCH_CORE: /xxxx/yyyy/Sites/licoriceDesign/perch/core
PERCH_RESFILEPATH: /xxxx/yyyy/Sites/licoriceDesign/perch/resources
Image manipulation: GD
PHP limits: Max upload 32M, Max POST 32M, Memory: 128M, Total max file upload: 32M
F1: 2edba60ed1f613d6dd804feb202456a2
Resource folder writeable: Yes
HTTP_HOST: localhost
DOCUMENT_ROOT: /xxxx/yyyy/Sites/licoriceDesign
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php

my checkout page

<?php if (!defined('PERCH_RUNWAY')) include($_SERVER['DOCUMENT_ROOT'].'/perch/runtime.php'); ?>

<?php
if (perch_member_logged_in() && perch_post('payment_method_nonce')) {

  // your 'success' return URL
  $return_url = '/shop/result';

  perch_shop_checkout('braintree', [
    'return_url' => $return_url,
    'token'      => perch_post('payment_method_nonce')
  ]);
}
?>
<?php perch_layout('global/header', [
  'title' => perch_page_title(true),
  'body-class' => 'home',
]); ?>
<?php
  perch_shop_payment_form('braintree');
?>

<?php perch_layout('global/footer'); ?>

and template

<div class="w3-row w3-padding-brain">
    <form action="" method="post">
        <div id="dropin-container"></div>
        <div>
            <input type="submit" value="Purchase" class="w3-btn w3-white w3-border w3-round w3-medium" />
        </div>
    </form>
</div>
<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
<script>
braintree.setup('<perch:shop id="client_token" escape="true" />', "dropin", {
  container: 'dropin-container',
  paypal: {
    singleUse: true,
    amount: <perch:shop id="amount" escape="true" />,
    currency: '<perch:shop id="currency" escape="true" />'
  },
});
</script>

shop.php settings are

'braintree' => [
        'enabled'   => false,
        'test_mode' => true,

plus my keys.
I haven't changed much. I'm getting the same response on the live server too. Thought it might be mamp at first but both the same.

William Chicken

William Chicken 1 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You need to switch the gateway to be enabled in your shop.php file.

That doesn't work. here is my complete file.

<?php
    return [

        /*
        |--------------------------------------------------------------------------
        | Gateway settings
        |--------------------------------------------------------------------------
        */

        'gateways' => [

            'default' => [
                'enabled'   => true,
                'test_mode' => true,
                'live' => [
                    'api_key'      => 'abc123',
                ],
                'test' => [
                    'api_key'      => 'abc123',
                ],
            ],

            'braintree' => [
        'enabled'   => true,
        'test_mode' => true,
        'live' => [
          'merchantId'  => 'abc123',
          'publicKey'   => 'def456',
          'privateKey'  => 'efghijklmnop987654321',
        ],
        'test' => [
          'merchantId'  => 'myxxxxxxxid',
          'publicKey'   => 'myxxxxxxxxkey',
          'privateKey'  => 'myxxxxxxxxkey',
        ],
      ],
    ],


    ];
?>

Should action have a url? It's just I thought it should load on the page it's on, then pass the checkout to result.

<form action="" method="post">
Drew McLellan

Drew McLellan 2638 points
Perch Support

If there's no action specified, the form will just submit back to itself.

Can you describe what you're seeing and where the error occurs?

If I fill out card details I get "There was an error processing your request. Try again". If choose paypal and proceed, it just reloads the page.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Back up even further. Where are you filling out details? Where does that message come from? What can you see on the screen. Remember I don't have your site in front of me.

It's the braintree form. So it's displaying. It has the paypal button. A card number field, expiration date field and cvv. below I have a purchase button. If I fill it out and press the button I get a load spinner then the message across the middle of the form in red.

Drew McLellan

Drew McLellan 2638 points
Perch Support

What happens if you click the PayPal button?

If I choose paypal and proceed, it just reloads the page. Of course I need it to take me to the results page, show success and empty the cart. Being sandboxed should it complete the process and how does it effect status? I'm wondering if that has something to do with it.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Clicking the PayPal button should open up a popup window with the PayPal UI in it, as far as I can see on my installation.

Do you see any errors in your browser console?

Yes it does do that sorry and gives me a sandbox paypal account with a button to click on which says 'proceed with sandbox purchase'.
I click on that and it loads it into the braintree form with this 'PayPal bt_buyer_us@paypal.com'.
I then click the main purchase button and the form just reloads itself.
I am then presented with the braintree form with all fields empty as if nothing has happened.

Paypal console error -
Blocked a frame with origin "https://checkout.paypal.com" from accessing a frame with origin "https://assets.braintreegateway.com". Protocols, domains, and ports must match. o i r global code

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, that's not something I've seen. Is it a CORS issue?

Hmm, This issue is only related to paypal as I get no js console error when I try with card. There is something about cors here https://developers.braintreepayments.com/reference/client-reference/javascript/v2/best-practices
but I don't know what has already been implemented in Perch behind the scenes.
I have followed the instructions provided on the perch braintree gateway page and so have the standard template.
Is there any settings you recommend I change or add in the braintree dashboard?

I've just updated the js to https://js.braintreegateway.com/js/braintree-2.28.0.min.js and am now getting js console error log

Object
details: {statusCode: 422, fieldErrors: Array}
message: "Credit card is invalid"
type: "SERVER"
Object Prototype

The card isn't invalid btw

Ok, so I have found this https://developers.braintreepayments.com/guides/credit-cards/testing-go-live/java . This lists all the card numbers so now my invalid error has gone away and the form doesn't give me the "There was an error processing your request. Try again" message.
So now I am getting the same response as when I use the Paypal option. Paypal console errors aside for one moment.
I enter the numbers and expiry date, then press Purchase. The spinning disk goes around and then nothing. I am still on the payment page.
Am I right in saying it should generate a token and then this should kick in

perch_shop_checkout('braintree', [ 
'return_url' => $return_url, 
'token' => perch_post('payment_method_nonce')
 ]); }

which would in turn send me to my results page?

I have it working. It was due to the address issue I've had in the past. The country ID not being set from the members account address. It seems i'm going to have to only let customers register via the shop app and leave the original member app register out of the equation. Thanks for your patience.