checkout / checkout-sdk-php

Checkout SDK for PHP
MIT License
48 stars 39 forks source link

Unable to capture payments through code #37

Closed parekhreena closed 5 years ago

parekhreena commented 5 years ago

Following the example here: https://github.com/checkout/checkout-sdk-php/wiki/2.-Payments

I tried below code but it fails with Response Code 404 The endpoint did not accept your request:


$additionalInformation = $payment->getAdditionalInformation();
            $invoiceId = $this->invoiceOrder->execute($orderId, false, $items, true);
            $invoice = $this->invoice->load($invoiceId);
            $storeCode = $this->storeManager->getStore($order->getStoreId())->getCode();
            $secretKey = $this->checkoutcomConfig->getValue('secret_key', null, $storeCode);

            $checkout = new CheckoutApi($secretKey);
            $payment = new \Checkout\Models\Payments\Capture($additionalInformation['transaction_info']['source']['id']);
            $payment->amount = $invoice->getGrandTotal();
            $capture = $checkout->payments()->capture($payment);

I also tried below which says invalid Request endpoint did not accept:

$data = [
                'methodId' => $paymentMethod,
                'cardBin' => $additionalInformation['transaction_info']['source']['bin'],
                'saveCard' => false,
                'source' => $paymentMethod,
                'cardToken' => $additionalInformation['transaction_info']['source']['fingerprint']
            ];

            $this->methodHandler
                ->get($paymentMethod)
                ->sendPaymentRequest(
                    $data,
                    $invoice->getGrandTotal(),
                    $order->getOrderCurrencyCode(),
                    $order->getIncrementId()
                );

Also tried below method which gives same error Endpoint did not accept request Error Code 400:

```

        $method = new \Checkout\Models\Payments\IdSource($additionalInformation['transaction_info']['source']['id']);
        $payment = new \Checkout\Models\Payments\Payment($method, $order->getOrderCurrencyCode());
        $payment->capture = true;
        $payment->amount = $invoice->getGrandTotal();
        $response = $checkout->payments()->request($payment);

Please let us know how we can capture partial payments programmatically. 
aquila-freitas-cko commented 5 years ago

Hi @parekhreena , Thanks for your question. The 404 means that the payment was not found, I assume $additionalInformation['transaction_info']['source']['id'] is not a valid pay_id (in your first example). The second example I couldn't understand very much, but the third one looks ok to me. Just make sure $invoice->getGrandTotal(); returns a integer value.

Just to clarify, you cannot capture a payment twice. If you want to partially capture a payment, remember to set $payment->capture = false; and manually capture with a new amount (equals or lower than the requested).

parekhreena commented 5 years ago

Hi @aquila-freitas-cko

Thank you for prompt response. for the third one I am sending intenger amount 100 and getting the reponse endpoint did not accept the request.

Also, if $additionalInformation['transaction_info']['source']['id'] is not the payment ID then please let me know where is it stored by checkout.com extension ? I also tried with $additionalInformation['transaction_info']['id'] and get the same error. I am using this module: https://github.com/checkout/checkout-magento-plugin

aquila-freitas-cko commented 5 years ago

Regarding the third example, I am struggling to replicate the issue. I assume it's on the gateway side.

On the last line, pass the HttpHandler::MODE_RETRIEVE as second parameter (like: $response = $checkout->payments()->request($payment, HttpHandler::MODE_RETRIEVE);). Then after that, do $response->serialize() show me the return of it. !Obs.! This will expose your secret key.

@avish-bisbeehurry-cko will help you with the magento1 soon.

parekhreena commented 5 years ago

@aquila-freitas-cko It's fine, I found the solution. Thank you for taking out the time to look into it with me. I am closing this ticket.