2014-01-28 19 views
0

以下代碼是我們用來爲用戶創建新訂閱的內容。如果用戶不存在,我們在運行createSubscription之前使用createAccount創建它們。爲新訂閱創建反覆返回「無效數據」

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(); 
} 

這是我們從recurly接收(我改變任何個人身份信息,但我們使用賬戶細節有效信息的響應:

<?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>[email protected]</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> 

我們'真的難倒了,錯誤信息反覆提供的是非常不明確和模糊的。任何幫助表示讚賞。

回答

2

返回的錯誤消息實際上是直接來自您的支付網關,而不是Recurly本身。查看交易數據應該提供更多有關下跌原因的信息。

如果您可以聯繫Recurly Support瞭解交易詳情,我們可以仔細研究一下,看看我們能否推斷出比網關提供的更多數據!