2Checkout / 2checkout-php

2Checkout PHP Library
MIT License
83 stars 66 forks source link

LineItems not in responce #16

Closed JAW-Dev closed 9 years ago

JAW-Dev commented 9 years ago

I can get a the response to reflect all the items except the line items.

here's my code

$line_items = array(
  'type'        => 'product',
  'price'       => $this->amount,
  'product_id'  => $subscription->id,
  'name'        => $subscription->name,
  'quantity'    => '1',
  'tangible'    => 'N',
  'startup_fee' => $subscription->fee,
  'recurrence'  => $subscription->duration . ' ' . $subscription->duration_unit,
  'description' => $subscription->description,
);
try {
  $charge = Twocheckout_Charge::auth(array(
    'sid'                          => $this->seller_id,
    'mode'                         => '2CO',
    'merchantOrderId'              => $this->subscription_id,
    'token'                        => $_POST['twoCheckoutToken'],
    'currency'                     => strtolower( $this->currency ),
    'total'                        => $this->amount,
    'billingAddr'                  => array(
      'name'      => $_POST['rcp_card_name'],
      'addrLine1' => $_POST['rcp_card_address'],
      'city'      => $_POST['rcp_card_city'],
      'state'     => $_POST['rcp_card_state'],
      'zipCode'   => $_POST['rcp_card_zip'],
      'country'   => $_POST['rcp_card_country'],
      'email'     => $this->email,
    ),
    "lineItems" => array(
      $line_items
    )
  ));
}

every step of the way the lineItems are there, but just not on the response, and it doesn't show recurring in the sandbox dashboard

craigchristenson commented 9 years ago

This issue is occurring because total is being passed along with the lineItems. When total is passed, the lineItems are ignored as they are not being used to calculate the total. If you remove total from your request the lineItems will be used on the sale and they will be listed on the sale in the sandbox dashboard. Please let me know if this resolves your issue or if I can help further.

JAW-Dev commented 9 years ago

I removed total, and even tried removing price, and it still didn't return a response with the lineItems or show it setup for recurring in the sandbox.

Which by the way, I don't think the sandbox is working correctly. I've been working on this all week, and every sale showed Approved in the admin (using the example info), but al of a sudden yesterday It started showing Pending Payout. Maybe there's something wrong with the sandbox?

craigchristenson commented 9 years ago

"Pending Payout" means that the sale was captured. 2Checkout intangible sales will capture automatically after passing fraud review. In the sandbox, the billing address is is used to determine the fraud status which will trigger the capture behind the scenes.

The issue is most likely with the values being passed. As I cannot see them in your example, I did a test in the sandbox using the same keys you are using and hard coded values and was able to create a recurring sale.

Request

<?php

require_once("lib/Twocheckout.php");

Twocheckout::privateKey("REDACTED");
Twocheckout::sellerId("REDACTED");
Twocheckout::sandbox(true);

try {
    $charge = Twocheckout_Charge::auth(array(
                "merchantOrderId" => "123",
                "token"     => ''REDACTED'',
                "currency"  => 'USD',
                "lineItems" => array(
                    array(
                        "type"        => 'product',
                        "price"       => "5.00",
                        "productId"  => "123",
                        "name"        => "Test Product",
                        "quantity"    => "1",
                        "tangible"    => "N",
                        "startupFee" => "1.00",
                        "recurrence"  => "1 Month",
                        "description" => "This is a test"
                    )
                ),
                "billingAddr" => array(
                    "name"      => 'Testing Tester',
                    "addrLine1" => '123 Test St',
                    "city"      => 'Columbus',
                    "state"     => 'OH',
                    "zipCode"   => '43123',
                    "country"   => 'USA',
                    "email"     => 'example@2co.com'
                )
            ));

    if ($charge['response']['responseCode'] == 'APPROVED') {
        print_r($charge);
   }
 } catch (Twocheckout_Error $e) {
     echo $e->getMessage();
 }

Response

Array
(
    [validationErrors] => 
    [response] => Array
        (
            [type] => AuthResponse
            [currencyCode] => USD
            [lineItems] => Array
                (
                    [0] => Array
                        (
                            [duration] => Forever
                            [options] => Array
                                (
                                )

                            [price] => 5.00
                            [quantity] => 1
                            [recurrence] => 1 Month
                            [startupFee] => 1.00
                            [productId] => 123
                            [tangible] => N
                            [description] => This is a test
                            [name] => Test Product
                            [type] => product
                        )

                )

            [transactionId] => 9093723345798
            [billingAddr] => Array
                (
                    [addrLine1] => 123 Test St
                    [addrLine2] => 
                    [city] => Columbus
                    [zipCode] => 43123
                    [phoneNumber] => 
                    [phoneExtension] => 
                    [email] => example@2co.com
                    [country] => USA
                    [name] => Testing Tester
                    [state] => OH
                )

            [shippingAddr] => Array
                (
                    [addrLine1] => 
                    [addrLine2] => 
                    [city] => 
                    [zipCode] => 
                    [phoneNumber] => 
                    [phoneExtension] => 
                    [email] => 
                    [country] => 
                    [name] => 
                    [state] => 
                )

            [merchantOrderId] => 123
            [orderNumber] => 9093723345789
            [recurrentInstallmentId] => 
            [responseMsg] => Successfully authorized the provided credit card
            [responseCode] => APPROVED
            [total] => 6.00
            [errors] => 
        )

    [exception] => 
)
JAW-Dev commented 9 years ago

Cool, I'll give it a try with hand coding the values again and replacing them one by one to find the issue.

JAW-Dev commented 9 years ago

OK so I figured out what was the issue. The membership system I'm building this for has "Day" as an option for recurrence. 2checkout doesn't accept "Day" as a recurrence option.

That's why I wasn't able to get it working. In the documentation it does state that, but I thought it was just an example, not the only options you can use.

Thanks for you help though.

craigchristenson commented 9 years ago

I'm glad to hear it man, sorry it wan't more clear. I'll see if the 2Checkout integrations team can get some better examples in the docs.

JAW-Dev commented 9 years ago

Yeah, that would be great. The documentation is vague in spots. There are a lot of areas that need explanation that don't have it.

rayanmurtaza commented 5 years ago

sir when i use currency 'PKR' then bad parameter error