[#1231] How can I add paymentMethod in custom payment(vipps)

Anonymous wrote:

Full Code:

require DIR . ‘/vendor/autoload.php’;

// Your SBPay token
const SBPAY_TOKEN = ‘xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx’;
// Your SBPay secret
const SBPAY_SECRET = ‘xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx’;
// Your SBPay merchant
const SBPAY_MERCHANT = ‘oncallfysioterapi’;
// SBPay host
const SBPAY_HOST = ‘https://app.sbpay.me/api/’;
// Host for your demo page
const HOST = ‘https://demo-custom-processor.com/’;

// request will come from SBPay with payment details in $_POST.
// You need to validate the request and then process it.
$client = new \SBPay\SBPayClient(
SBPAY_TOKEN, SBPAY_SECRET,
SBPAY_MERCHANT, SBPAY_HOST
);

$order = $client->payments()->approveOrder(
1263, ‘custom’, ‘’,
‘’, ‘’, ‘custom’
);
print_r($order); exit;
print_r($order); exit;
try {
// Validate request that comes from SBPay
$client->payments()->validateCustomPaymentProcessorRequest($_POST);
} catch (\SBPay\Exceptions\Exception $e) {
// handle exception. Just show error message for demo purposes
die($e->getMessage());
}

Dmytro Bondarev wrote:

As you can see you are getting error. Because you are not passing mandatory fields.
Please try:

$client->payments()->approveOrder(1263, ‘Approved by custom payment processor’, ‘vipps’);

Anonymous wrote:

Just tested code.
But error is same.

Fatal error: Uncaught SBPay\Exceptions\BadRequestException: Validation error in D:\work\xampp-8\htdocs\vendor\sbpay\sdk\lib\SBPayClient.php:167 Stack trace: #0 D:\work\xampp-8\htdocs\vendor\sbpay\sdk\lib\SBPayClient.php(226): SBPay\SBPayClient->request(‘POST’, ‘/order/1263/app…’, ‘{“reason”:"Paym…’, ‘5e9115a015dbb60…’) #1 D:\work\xampp-8\htdocs\vendor\sbpay\sdk\lib\SBPayClient.php(243): SBPay\SBPayClient->signedRequest(‘POST’, ‘/order/1263/app…’, Array) #2 D:\work\xampp-8\htdocs\vendor\sbpay\sdk\lib\SBPayPayments.php(51): SBPay\SBPayClient->signedPost(‘/order/1263/app…’, Array) #3 D:\work\xampp-8\htdocs\sbpay.php(47): SBPay\SBPayPayments->approveOrder(1263, ‘Payment process…’, ‘Custom PayPal’) #4 {main} thrown in D:\work\xampp-8\htdocs\vendor\sbpay\sdk\lib\SBPayClient.php on line 167

Just checked approvrOrder function in SDK.


public function approveOrder(
        int $id, string $reason, string $paymentMethod, ?string $transactionId = null,
        ?string $paymentMethodReferenceId = null, ?string $paymentMethodName = null
    ): void
    {
        $paymentMethodInformation = null;
        if ($paymentMethodReferenceId && $paymentMethodName) {
            $paymentMethodInformation = [
                'paymentMethodReferenceId' => $paymentMethodReferenceId,
                'paymentMethodName' => $paymentMethodName
            ];
        }
        
        $this->client()->signedPost(
            '/order/' . $id . '/approve',
            [
                'reason' => $reason,
                'paymentMethod' => $paymentMethod,
                'transactionId' => $transactionId,
                'paymentMethodInfo' => $paymentMethodInformation
            ]
        );
    }

As you can see, 3rd param is paymentMethod.(vipps)


$client->payments()->approveOrder(1263, 'Approved by custom payment processor', 'vipps');

I got the data about order_id =1263 for check paymentMethod.


$order = $client->payments()->approveOrder(1832);

You can check data in here.
https://vipps.fysioretthjem.no/sb.php

Payment method is null.

Please let me know correct 3rd params.


$client->payments()->approveOrder(1263, 'Approved by custom payment processor', 'vipps');

Anonymous wrote:

sorry, missed one.
I got the data about order_id =1263 for check paymentMethod.


$client->payments()->getOrder(1263)

Dmytro Bondarev wrote:

Hi,
First of all approveOrder method does not return any data.
Your request failed when you call approveOrder please provide full response. Without it we can not help you.
If approveOrder failed nothing will be changed in your order, we do not need any details of order.