Make payment in php to RAPYD COLLECT

Am trying to make payments to a wallets using Rapyd Collect in php following the 2 sample code below but it print null Value as result

https://docs.rapyd.net/build-with-rapyd/reference/payment-object

sample code 1;


<?php


$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/payments/utilities.php";
include($path);
$body = [
    'receipt_email' => 'johndow@rapyd.net',
     "amount"=> 100,
    "currency"=> "USD",
    "description"=> "Payment by card token",
    "payment_method"=> "card_823894ee89c52be00e76d2be10116672",
    "complete_payment_url"=> "http://localhost/success.php",
  "ewallets"=> [
            "ewallet"=> "ewalletmy-ewallet-id-goes-here",
            "percentage"=> 100
        
    ],

     "address"=> [
        "name"=> 'John Doe',
        "line_1"=> '123 Main Street',
        "line_2"=> 'Penthouse',
        "line_3"=> '',
        "city"=> 'Anytown',
        "district"=> '',
        "canton"=> '',
        "state"=> 'NY',
        "country"=> 'US',
        "zip"=> '12345',
        "phone_number"=> '16125551234'
      ]
];

try {
    $object = make_request('post', '/v1/payments/payment_19e3edad1e9102cd24006a34c52c9a0b', $body);
    var_dump($object);
} catch(Exception $e) {
    echo "Error: $e";
}

exit();

?>

I think the problem is value for payment_19e3edad1e9102cd24006a34c52c9a0b or card_823894ee89c52be00e76d2be10116672.

What are they. how can I solve the issue


**sample code 2:**

This sample code 2 below also displays **null value** as result. It seems some parameters needed to be passed as objects or arrays. can someone hep me out

<?php
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/payments/utilities.php";
include($path);
$body = [
    'receipt_email' => 'johndow@rapyd.net',
     "amount"=> 100,
    "currency"=> "USD",
    "description"=> "Payment by card token",
  "ewallets"=> [
            "ewallet"=> "ewalletmy-ewallet-id-goes-here",
            "percentage"=> 100 
    ],
"metadata"=> [
        "merchant_defined"=> true
    ],

    "payment_method"=> [
    "type"=> "is_visa_card",
    "fields"=> [
        "name"=> "Test User",
        "number"=> "4111111111111111",
        "expiration_month"=> "08",
        "expiration_year"=> "24",
        "cvv"=> "789"
    ],
    "complete_payment_url"=> "http://localhost/success.php",
    "error_payment_url"=> "http://localhost/error.php"
    ],



     "address"=> [
        "name"=> 'John Doe',
        "line_1"=> '123 Main Street',
        "line_2"=> 'Penthouse',
        "line_3"=> '',
        "city"=> 'Anytown',
        "district"=> '',
        "canton"=> '',
        "state"=> 'NY',
        "country"=> 'US',
        "zip"=> '12345',
        "phone_number"=> '16125551234'
      ]
];

try {
    $object = make_request('post', '/v1/payments', $body);
    var_dump($object);
} catch(Exception $e) {
    echo "Error: $e";
}



?>

I answered this on Slack. See https://formula0001ra-ofh1119.slack.com/archives/C0233AFKP4N/p1623965202208900

[REPOSTING FROM SLACK]:

Regarding your first example, I note the following points:

  • You are mixing quotes - some are single and some are double. It might be better to stick with one style.
  • The body of your request looks like a β€˜Create Payment’, but in your try block, you are using β€˜Update Payment’, which will ignore most of what you put in the body.
  • Your use of the card ID implies that the card has previously been added to a customer or created with β€˜Create Card Token - Hosted Page’
  • In the β€˜ewallet’ field, you must put the Rapyd ID of a previously created Rapyd Wallet, which is a string starting with ewallet_. If you omit it, the payment will go into your Rapyd-defined client wallet, which may or may not be the one you want.

Regarding your second example, I note the following:

  • payment_method needs to be an array (PHP array)
  • fields needs to be a PHP array
  • each ewallet JSON object needs to be a PHP array
  • If you want to use address for this example, then it needs to be a PHP array, too.

See the PHP example on Create Group Payment for examples of the syntax.