Forum

Thread tagged as: Question, Shop

CountryID with Perch Shop & Braintree

I'm having trouble with checkout via Braintree.

I'm currently testing in sandbox and the payment is coming back failed with the following debug message:

...
SELECT * FROM perch2_shop_customers WHERE customerID='11' AND customerDeleted IS NULL LIMIT 1
[1] SELECT * FROM perch2_shop_addresses WHERE addressID=82 AND addressDeleted IS NULL LIMIT 1
[1] SELECT * FROM perch2_shop_addresses WHERE addressID=81 AND addressDeleted IS NULL LIMIT 1
[1] SELECT * FROM perch2_shop_countries WHERE countryID='0' LIMIT 1
No country set for address
[1] SELECT * FROM perch2_shop_countries WHERE countryID='0' LIMIT 1
No country set for address
Payment failed
...

My checkout doesn't require an address, the goods that are being sold through the site are collected from the store so there is no need for a shipping address, but do I still require a billing address for this to work? I was hoping I could just register a user with first name, last name, phone and email (passwordless) and then take credit card details for payment. I also tried setting a default for the country during registration with a hidden field <perch:input type="hidden" id="country_name" value="157" /> but that does not seem to work.

Here is some more of the debug, including the response from Braintree:

...
                    [params] => Array
                        (
                            [transaction] => Array
                                (
                                    [type] => sale
                                    [amount] => 20.00
                                    [orderId] => 35
                                    [paymentMethodNonce] => dab7bd21-bbc9-0e00-2588-d95c0c05ce5c
                                    [billing] => Array
                                        (
                                            [company] => false
                                            [firstName] => Hamish
                                            [lastName] => Irving
                                            [streetAddress] => false
                                            [extendedAddress] => false
                                            [locality] => false
                                            [postalCode] => false
                                            [region] => false
                                            [countryName] => false
                                        )

                                    [shipping] => Array
                                        (
                                            [company] => false
                                            [firstName] => Hamish
                                            [lastName] => Irving
                                            [streetAddress] => false
                                            [extendedAddress] => false
                                            [locality] => false
                                            [postalCode] => false
                                            [region] => false
                                            [countryName] => false
                                        )

                                    [options] => Array
                                        (
                                            [submitForSettlement] => true
                                        )

                                )

                        )

                    [message] => Country name is not an accepted country.
                    [creditCardVerification] => 
                    [transaction] => 
                    [subscription] => 
                    [merchantAccount] => 
                    [verification] => 
                )
...
Hamish Irving

Hamish Irving 1 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

It should be enough to set the country as a hidden field, yes.

Thanks, thats encouraging, however it isn't collecting the country. Can you see any errors with what I am doing?

My registration form register.html

        <perch:form id="register" method="post" app="perch_shop" next="checkout">

            <div class="form inline">
                <perch:label for="first_name">First name:*</perch:label>
                <perch:input type="text" id="first_name" required="true" label="First name" />
                <perch:error for="first_name" type="required">Please add your name</perch:error>
            </div>
            <div class="form inline">
                <perch:label for="last_name">Last name:*</perch:label>
                <perch:input type="text" id="last_name" required="true" label="Last name" />
                <perch:error for="last_name" type="required">Please add your name</perch:error>
            </div>
            <div class="form inline">
                <perch:label for="email">Email:*</perch:label>
                <perch:input type="email" id="email" required="true" helper="PerchMembers_Members::check_email" />
                <perch:error for="email" type="required">Please add your email address</perch:error>
                <perch:error for="email" type="helper">That email address is already in use</perch:error>
                <perch:input type="hidden" id="password" value="__auto__" />
            </div>
            <div class="form inline">
                <perch:label for="phone">Phone:*</perch:label>
                <perch:input type="phone" id="phone" required="true" label="Phone" />
                <perch:error for="phone" type="required">Please add your phone number</perch:error>
            </div>

            <div>
                <perch:input type="hidden" id="country" value="157" />
            </div>

            <p>All fields are required.</p>

            <div class="form-button">
                <perch:input type="submit" value="Register" />
            </div>

        </perch:form>

Called on my register.php page

<?php perch_shop_registration_form([
          'template' => 'checkout/register.html',
        ]); ?>
Rachel Andrew

Rachel Andrew 394 points
Perch Support

You are setting a country number there, it seems to want a country name based on that message. Have you checked to see what it is expecting?

Hi Rachel, not sure how I should check to see what it is expecting? I'm assuming Perch needs to accept a country first and then pass it to Braintree?

Drew McLellan

Drew McLellan 2638 points
Perch Support

We do also check for address_1 being set as evidence of an address being correctly configured, so you could set that to a fixed value and see if that helps.

OK, I've got both the countryID and address_1 populating in the DB, I can see in perch2_shop_addresses table..

However, now after I click to submit a payment in sandbox, I get the following error on my checkout.php page after it submits to Braintree?

Fatal error: Call to a member function customerFirstName() on boolean in /nfs/c12/h08/mnt/213490/domains/yarrows.co.nz/html/perch/addons/apps/perch_shop/lib/gateways/PerchShopGateway_default.class.php on line 239
Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you checking the customer is logged in before checkout?

Yes, using the following on checkout.php page


if (perch_member_logged_in() && perch_post('payment_method_nonce')) { $return_url = '/confirmation'; perch_shop_checkout('braintree', [ 'return_url' => $return_url, 'token' => perch_post('payment_method_nonce') ]); } ?>

OK, managed to get it working - I could see from the perch2_shop_countries table that countryID is expecting a number (in my case New Zealand = 157)

Having both countryID and address_1 set has got it working