Skip to content
This repository has been archived by the owner on Nov 8, 2021. It is now read-only.

getInvoice #24

Open
didiandalucia opened this issue Nov 8, 2019 · 9 comments
Open

getInvoice #24

didiandalucia opened this issue Nov 8, 2019 · 9 comments

Comments

@didiandalucia
Copy link

brings everytime an error:

Status Code: 403; Forbidden

and in the server:

info: BTCPayServer.Security.Bitpay.BitpayAuthenticationHandler: AuthenticationScheme: Bitpay was forbidden.
info: BTCPayServer.Security.Bitpay.BitpayAuthenticationHandler: AuthenticationScheme: Bitpay was forbidden.

@NicolasDorier
Copy link
Member

please share the code.

@didiandalucia

This comment has been minimized.

@didiandalucia
Copy link
Author

`<?php
/**

  • Copyright (c) 2014-2017 BitPay
  • getInvoice
  • Requirements:
    • Baisic PHP Knowledge
    • Private and Public keys from 001.php
    • Token value obtained from 002.php
    • Invoice created
      /
      require DIR . '/../../../../../vendor/autoload.php';
      // Now fetch the invoice from BitPay
      $client = new \BTCPayServer\Client\Client();
      $adapter = new \BTCPayServer\Client\Adapter\CurlAdapter();
      $client->setUri('https://:443');
      $client->setAdapter($adapter);
      $token = new \BTCPayServer\Token();
      $token->setToken(''); // UPDATE THIS VALUE
      $client->setToken($token);
      /
      *
  • This is where we will fetch the invoice object
    */
    $invoice = $client->getInvoice("Py3soohUrGKzRKQPUXk94V"); // last invoice id
    $request = $client->getRequest();
    $response = $client->getResponse();
    echo (string)$request . PHP_EOL . PHP_EOL . PHP_EOL;
    echo (string)$response . PHP_EOL . PHP_EOL;
    print_r($invoice);
    ?>`

@NicolasDorier
Copy link
Member

I cna't tell why with what you are sharing. You can just activate "Allow anyone to create invoice" in your store settings / pay button.

@didiandalucia
Copy link
Author

Store setting "Allow anyone to create invoice" is set!

@Alldebrid
Copy link

Alldebrid commented Jan 30, 2020

We met the same issue, and it was resolved by adding this when getting the invoice, before injecting the token in the client :

$token->setFacade('merchant');

This line is missing from a few places in the tutorial scripts, just like the private / public keys from IPNlogger.php.

I'll make a few push requests in a few days when I have time, as your project is really stellar !

@NicolasDorier
Copy link
Member

@Alldebrid this is strange, the facade should be ignored by btcpayserver.
Do you know exactly which call did not worked?

@he3117
Copy link

he3117 commented Apr 20, 2020

I'm getting 403 error too. I don't know what cause the problem. in server log it just say AuthenticationScheme: Bitpay was forbidden. example code for php is buggy and not working. some one with more experience with the project please fix the tutorial code. Or add more detail to the error log. I have the token and I updated the token value. I want to create invoice with code from tutorial 3.
I'm testing on local host but BTCPayserver is not on localhost. if some one have a working code for simple php invoice please share.

@nakkapeddi
Copy link

Hey folks, for those having trouble with this, here are the steps:

First, you should create the pairing request with the API client. This is how I do it in Golang:

        pemString := ku.GeneratePem()
	id := ku.GenerateSinFromPem(pemString)
	webClient := client.Client{ApiUri: BTCPAYSERVER, Insecure: true, Pem: pemString, ClientId: id}
	token, err := webClient.PairWithFacade("merchant")
	if err != nil {
		log.Println("error sending request")
		return
	}
	webClient.Token = token
	log.Printf("%+v\n", webClient)
	BTCPAYCLIENT = &webClient

This will generate the pairingCode that you must authorize server-side. The pairingCode is inside "Token" JSON payload that is returned to you by the server. You must MANUALLY authorize this token in the UI, by going to "http://yourbtcpayserver/api-access-request?pairingCode=xxxyyyzzz". Verify that the clientID is the same. Then authorize it. Then it will say pairing successful. Before this you cannot use that client to do anything, because the server will not recognize it. Hope it helps.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants