0

I'm trying to create a simple checkout page with wepay and my checkout code (taken from the SDK sample) works great for the owner (me) when I'm signed in, but when logged in as a different user who hasn't created the account (under theirs?) it says the account is invalid or does not belong to the user.

So how are new logged in users supposed to pay to the account (mine), in other words make payments?

Here is the code for reference. The account_id doesn't work for new logged in users because they haven't created it.

$wepay = new WePay($_SESSION['wepay_access_token']);

$checkout = $wepay->request('checkout/create', array(
    'account_id' => 501999810,
    'amount' => 1.00,
    'currency'=> 'USD',
    'short_description'=> 'Selling 42 Pens',
    'type'=> 'goods'
));

Maybe I have something completely off, but that account_id is where I want to receive payments?

Any help would be appreciated!

user1367323
  • 361
  • 2
  • 7
  • [WePay SDK Readme](https://github.com/wepay/PHP-SDK/blob/master/README.md#authentication) clearly says "To obtain an access token for your user, you must redirect the user to WePay for authentication". Then `user_id` is returned in [access token response](https://developer.wepay.com/api-calls/oauth2#token). – Tushar Sharma Apr 20 '17 at 20:34
  • Thank you for your response. I was able to implement a login redirect and get the new user access token using the oauth2/token request, but the problem still presists. With the new test user that logged in he has no accounts (when I log into his wepay acct) under him. So if we want to receive payment to the site account (in this case 501999810) do we somehow add that account under his? – user1367323 Apr 20 '17 at 20:59

2 Answers2

1

Once you register the user, you have to create an actual merchant account by calling /account/create.

Once you have the user's access token, you can call /account/create with the user's access token and the relevant info to actually attach an account to the user. The /account/create call will return an account_id. That account_id is the one you use in the /checkout/create call.

So until you create an account via /account/create the user cannot accept payments.

TheF1rstPancake
  • 2,318
  • 17
  • 17
0
     $productData['data']['seller_data']['wepay_access_token']="STAGE_ea6cd2dffa3dfa23bd4817f210936fadada9fa91e906f353e15813c6cf920fb8";
     $productData['data']['seller_data'}['wepay_account_id']="287443494";
     $wepay = new WePay($productData['data']['seller_data']['wepay_access_token']);
     $checkOutData = array(
        //"account_id" => 12345678,
        "account_id" => $productData['data']['seller_data'}['wepay_account_id'],
        "amount" => 500,
        "type" => "goods",
        "currency" => "USD",
        "short_description" => "Purchase made at test site",
        "long_description" => "The charges made in this payment are of the order placed in test",
        "delivery_type" => "point_of_sale",
        "fee" => array(
            "app_fee" => 15,
            //'fee_payer' => 'payer_from_app'
            'fee_payer' => 'payee_from_app'
        ),
        //"auto_release"=>false,
        "payment_method" => array(
            "type" => "credit_card",
            "credit_card" => array(
                "id" => 2178689241,
                "auto_capture" => false
            )
        )
    );
    try {
        $checkoutResult = $wepay->request('checkout/create', $checkOutData);
    } catch (Exception $e) {
        $data['status'] = '0';
        $data['message'] = 'We could not complete checkout!';
        return $this->SetOutput();
    }






You can get seller access token and account id using 


                   $user_id=20;
                    $access_token="STAGE_ea6cd2dffa3dfa23bd4817f210936fadada9fa91e906f353e15813c6cf920fb8":
                    $userName="test user";
                    $description="sell products";
                    try {
                    $wepay = new WePay($access_token);
                    if (empty($userName)) {
                        try {
                            $uresponse = $wepay->request('/user');
                            $userName = $uresponse->user_name;
                        } catch (WePayException $e) {
                            $uresponse['status'] = '0';
                            $uresponse['message'] = $e->getMessage();
                            return $uresponse;
                        }
                    }
                    $response = $wepay->request('account/create/', array(
                        'name' => $userName,
                        'description' => $description,
                        'reference_id' => '"' . $user_id . '"'
                    ));
                } catch (WePayException $e) {
                    $response['status'] = '0';
                    $response['message'] = $e->getMessage();
                    return $response;
                }