Question

The code below is what we're using to try and create a new subscription for a user. If the user doesn't already exist, we create them using createAccount before running createSubscription.

public function createAccount($recurlyId, $email, $firstName, $lastName)
{
    if ($this->getAccount($recurlyId) === null)
    {
        $account = new Recurly_Account($recurlyId);
        $account->email = $email;
        $account->first_name = $firstName;
        $account->last_name = $lastName;
        $account->create();
    }
}

public function createSubscription($recurlyId, $planCode, CardBillingInformation $billingInfo, $startDate = null)
{
    if (($account = $this->getAccount($recurlyId)) === null) throw new CHttpException(400, 'You are trying to create a subscription for an account that doesn\'t exist');

    $account->billing_info = new Recurly_BillingInfo();
    $account->billing_info->number = $billingInfo->number;
    $account->billing_info->year = (int) $billingInfo->year;
    $account->billing_info->month = (int) $billingInfo->month;
    $account->billing_info->address1 = $billingInfo->address1;
    $account->billing_info->city = $billingInfo->city;
    $account->billing_info->country = $billingInfo->country;
    $account->billing_info->zip = $billingInfo->zip;

    $subscription = new Recurly_Subscription();
    $subscription->plan_code = $planCode;
    $subscription->currency = 'GBP';
    $subscription->account = $account;
    if ($startDate !== null) $subscription->starts_at = $startDate;

    $subscription->create();
}

This is the response that we're receiving from recurly (I've altered any personally identifiable information, but the account details we're using are valid details:

<?xml version="1.0" encoding="UTF-8"?>
<errors>
    <transaction_error>
        <error_code>invalid_data</error_code>
        <error_category>hard</error_category>
        <merchant_message>The payment gateway declined the transaction due to invalid data. Please check the response details for more information.</merchant_message>
        <customer_message>The transaction was declined due to invalid data.</customer_message>
    </transaction_error>
    <error field="subscription.account.base" symbol="invalid_data">The transaction was declined due to invalid data.</error>
    <transaction href="https://SOMEACCOUNT.recurly.com/v2/transactions/254720b963dcb40226e8064229a1ce24" type="credit_card">
    <account href="https://SOMEACCOUNT.recurly.com/v2/accounts/3368d152-2a8b-11e3-a3de-22000a24db56"/>
    <subscription href="https://SOMEACCOUNT.recurly.com/v2/subscriptions/254720b91850041f76a17d42f0a66b54"/>
    <uuid>254720b963dcb40226e8064229a1ce24</uuid>
    <action>purchase</action>
    <amount_in_cents type="integer">1800</amount_in_cents>
    <tax_in_cents type="integer">300</tax_in_cents>
    <currency>GBP</currency>
    <status>declined</status>
    <payment_method>credit_card</payment_method>
    <reference nil="nil"/>
    <source>subscription</source>
    <recurring type="boolean">false</recurring>
    <test type="boolean">false</test>
    <voidable type="boolean">false</voidable>
    <refundable type="boolean">false</refundable>
    <transaction_error>
        <error_code>invalid_data</error_code>
        <error_category>hard</error_category>
        <merchant_message>The payment gateway declined the transaction due to invalid data. Please check the response details for more information.</merchant_message>
        <customer_message>The transaction was declined due to invalid data.</customer_message>
    </transaction_error>
    <cvv_result code="" nil="nil"/>
    <avs_result code="" nil="nil"/>
    <avs_result_street nil="nil"/>
    <avs_result_postal nil="nil"/>
    <created_at type="datetime">2014-01-28T10:11:57Z</created_at>
    <details>
        <account>
            <account_code>3368d152-2a8b-11e3-a3de-22000a24db56</account_code>
            <first_name>An</first_name>
            <last_name>Other</last_name>
            <company/>
            <email>a_user9@hotmail.com</email>
            <billing_info type="credit_card">
                <first_name>An</first_name>
                <last_name>Other</last_name>
                <address1>123 Fake St</address1>
                <address2 nil="nil"/>
                <city>Townsville</city>
                <state nil="nil"/>
                <zip>TV23 6EU</zip>
                <country>GB</country>
                <phone nil="nil"/>
                <vat_number/>
                <card_type>Visa</card_type>
                <year type="integer">2014</year>
                <month type="integer">9</month>
                <first_six>xxxxxx</first_six>
                <last_four>xxxx</last_four>
            </billing_info>
        </account>
    </details>
</transaction>
</errors>

We're really stumped and the error message recurly provides is incredibly unspecific and vague. Any help is appreciated.

Was it helpful?

Solution

The error message returned is actually coming directly from your payment gateway, rather than Recurly itself. Viewing the transaction data should provide a bit more information about the reason for the decline.

If you can contact Recurly Support with the transaction details we can take a closer look and see if we can deduce more data than the gateway is providing!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top