1

im trying to create a customer in paymaya using curl in php. im following this documentation http://developers.paymaya.com.payment-vault.s3-website-ap-southeast-1.amazonaws.com/#card-vault-customers-post

but its not returning the right response(it returns nothing)

<?php
require_once(DIR_VENDOR . 'PayMaya-PHP-SDK-master/sample/autoload.php');

Class Paymaya {

    public function paymayaInit(){
        PayMayaSDK::getInstance()->initCheckout("pk-nRO7clSfJrojuRmShqRbihKPLdGeCnb9wiIWF8meJE9", "sk-jZK0i8yZ30ph8xQSWlNsF9AMWfGOd3BaxJjQ2CDCCZb", "SANDBOX");
    }

    public function createCustomer(){
        $this->paymayaInit();

        // $ch = curl_init("https://pg-sandbox.paymaya.com/payments/v1/customers");
        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, "https://pg-sandbox.paymaya.com/payments/v1/customers");
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Basic c2stOWxSbUZUVjhCSWR4b1hXbTVsaURBbEtGMHlMNGdaendtRFFBbW52eFdPRjo="));

        curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);

        $body = array(
                  "firstName" => "Ysa",
                  "middleName" => "Cruz",
                  "lastName" => "Santos",
                  "birthday" => "1987-10-10",
                  "sex" => "F",
                  "contact" => array(
                                    "phone" => "+63(2)1234567890",
                                    "email" => "ysadcsantos@gmail.com"
                                  ),
                  "billingAddress" => array(
                                    "line1" => "9F Robinsons Cybergate 3",
                                    "line2" => "Pioneer Street",
                                    "city" => "Mandaluyong City",
                                    "state" => "Metro Manila",
                                    "zipCode" => "12345",
                                    "countryCode" => "PH"
                                  ),
                  "metadata" => array()
                );

        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($body));
        $response = curl_exec($ch);
        curl_close($ch);

        // die(print_r($response));
        return json_decode($response);
    }

}

here is my class. does anyone already tried integrating paymaya in php? also i have to comment the namespace in PayMayaSDK.php to be able to use PayMayaSDK class

mendz
  • 463
  • 2
  • 5
  • 16

1 Answers1

1

Thanks for your credentials posted in question I made few requests and found what was wrong.

First of all I used curl_error($ch) to find out what error was.

It's The requested URL returned error: 400 Bad Request.

Problem is that you set Content-Type to be json, but sending URL encoded query.

Change http_build_query to json_encode

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://pg-sandbox.paymaya.com/payments/v1/customers");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Basic c2stOWxSbUZUVjhCSWR4b1hXbTVsaURBbEtGMHlMNGdaendtRFFBbW52eFdPRjo="));

curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);

$body = array(
    "firstName" => "Ysa",
    "middleName" => "Cruz",
    "lastName" => "Santos",
    "birthday" => "1987-10-10",
    "sex" => "F",
    "contact" => array(
        "phone" => "+63(2)1234567890",
        "email" => "ysadcsantos@gmail.com"
    ),
    "billingAddress" => array(
        "line1" => "9F Robinsons Cybergate 3",
        "line2" => "Pioneer Street",
        "city" => "Mandaluyong City",
        "state" => "Metro Manila",
        "zipCode" => "12345",
        "countryCode" => "PH"
    ),
    "metadata" => array()
);

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
$response = curl_exec($ch);
echo __FILE__."@".__LINE__."<pre>";
var_dump($response, curl_error($ch));
echo "</pre>";
curl_close($ch);
Justinas
  • 41,402
  • 5
  • 66
  • 96
  • its ok sir the credentials are for testing environment only provided in the paymaya website. i also tried using curl_error() but my error is different its "SSL certificate problem: unable to get local issuer certificate" – mendz May 16 '18 at 06:02
  • @mendz Try disabling SSL verification https://stackoverflow.com/questions/15135834/php-curl-curlopt-ssl-verifypeer-ignored – Justinas May 16 '18 at 07:44
  • wow thanks bro been wondering if that is possible haha. thank you – mendz May 17 '18 at 04:35